|
| Kommentar Fra : Guild |
Dato : 17-12-04 13:38 |
| | |
| Kommentar Fra : natmaden |
Dato : 17-12-04 17:24 |
|
Denne beregner tiden til en given dato og tid.
Det er javascript, men måske du kan bruge det.
Kode <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Nedtælling</title>
</head>
<body>
<script language="JavaScript1.2">
function setcountdown(theyear,themonth,theday){
yr=theyear;mo=themonth;da=theday
}
// nedtæl til (år, måned, dag):
setcountdown(2004,12,24)
var occasion="Jul"
var message_on_occasion="Glædelig Jul"
var countdownwidth='560px'
var countdownheight='40px'
var countdownbgcolor='#E0E0A0'
var opentags='<font face="Tahoma">Der er<br>'
var closetags='</font>'
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
var crosscount=''
function start_countdown(){
if (document.layers)
document.countdownnsmain.visibility="show"
else if (document.all||document.getElementById)
crosscount=document.getElementById&&!document.all?document.getElementById("countdownie") : countdownie
countdown()
}
if (document.all||document.getElementById)
document.write('<span id="countdownie" style="width:'+countdownwidth+'; background-color:'+countdownbgcolor+'"></span>')
window.onload=start_countdown
function countdown(){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todayh=today.getHours()
var todaymin=today.getMinutes()
var todaysec=today.getSeconds()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
futurestring=montharray[mo-1]+" "+da+", "+yr
dd=Date.parse(futurestring)-Date.parse(todaystring)
dday=Math.floor(dd/(60*60*1000*24)*1)
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
// På dagen
if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+message_on_occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+message_on_occasion+closetags
return
}
//Efter dagen
else if (dday<=-1){
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+"Begivenheden er overstået! "+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+"Begivenheden er overstået! "+closetags
return
}
//eller vis tid tilbage
else{
if (document.layers){
document.countdownnsmain.document.countdownnssub.document.write(opentags+dday+ " dage, "+dhour+" timer, "+dmin+" minutter, og "+dsec+" sekunder "+occasion+closetags)
document.countdownnsmain.document.countdownnssub.document.close()
}
else if (document.all||document.getElementById)
crosscount.innerHTML=opentags+dday+ " dage, "+dhour+" timer, "+dmin+" minutter, og "+dsec+" sekunder til "+occasion+closetags
}
setTimeout("countdown()",1000)
}
</script>
<ilayer id="countdownnsmain" width=&{countdownwidth}; height=&{countdownheight}; bgColor=&{countdownbgcolor}; visibility=hide>
<layer id="countdownnssub" width=&{countdownwidth}; height=&{countdownheight}; left=0 top=0>
</layer>
</ilayer>
</body>
</html> |
Natmaden.
| |
| Kommentar Fra : crha |
Dato : 17-12-04 19:50 |
|
Tak for jeres kommentarer
Guild: Jeg har kigget på siden, men kan intet sted finde noget om VB koder.
Harlekin: Jeg tror ikke jeg kan finde ud af at bruge den rigtigt, kan du komme med et eksempel? Den laver fejl hver gang jeg forsøger mig frem.
Natmaden: Mange tak, men jeg kan desværre ikke bruge JavaScript til dette.
| |
|
Brug DateDiff-funktionen!
Indsæt følgende som et modul:
Option Explicit
Dim intDiffInMinutes, intDiffInHours, strHour, strMinute
Public Function Tidsforskel(Date1 As Date, Date2 As Date)
intDiffInMinutes = DateDiff("n",Date1,Date2,vbMonday,vbUseSystem)
If (intDiffInMinutes Mod 60) = 0 Then
intDiffInHours = (intDiffInMinutes / 60)
intDiffInMinutes = 0
Else
intDiffInHours = Fix(intDiffInMinutes / 60)
intDiffInMinutes = intDiffInMinutes - (intDiffInHours*60)
End If
If intDiffInHours <> 1 Then
strHour = "timer"
Else
strHour = "time"
End If
If intDiffInMinutes <> 1 Then
strMinute = "minutter"
Else
strMinute = "minut"
End If
Tidsforskel = "Der er " & intDiffInHours & " " & strHour & " og " & intDiffInMinutes & " " & strMinute & " fra " & Date1 & " til " & Date2 & "!"
End Function
| |
| Accepteret svar Fra : natmaden | Modtaget 50 point Dato : 20-12-04 07:30 |
|
hmm !
lånt fra VB5
Kode Option Explicit
Private Sub Form_Load()
' This example uses the DateDiff function to display the number of days between a given date and today.
Dim TheDate As Date ' Declare variables.
Dim Msg
TheDate = InputBox("Enter a date")
Msg = "Days from today: " & DateDiff("d", Now, TheDate)
MsgBox Msg
End Sub |
Citat DateDiff Function
Returns a Variant (Long) specifying the number of time intervals between two specified dates.
Syntax
DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
The DateDiff function syntax has these named arguments:
Part Description
interval Required. String expression that is the interval of time you use to calculate the difference between date1 and date2.
date1, date2 Required; Variant (Date). Two dates you want to use in the calculation.
firstdayofweek Optional. A constant that specifies the first day of the week. If not specified, Sunday is assumed.
firstweekofyear Optional. A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.
Settings
The interval argument has these settings:
Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week
h Hour
n Minute
s Second
The firstdayofweek argument has these settings:
Constant Value Description
vbUseSystem 0 Use the NLS API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday
The firstweekofyear argument has these settings:
Constant Value Description
vbUseSystem 0 Use the NLS API setting.
vbFirstJan1 1 Start with week in which January 1 occurs (default).
vbFirstFourDays 2 Start with the first week that has at least four days in the new year.
vbFirstFullWeek 3 Start with first full week of the year.
Remarks
You can use the DateDiff function to determine how many specified time intervals exist between two dates. For example, you might use DateDiff to calculate the number of days between two dates, or the number of weeks between today and the end of the year.
To calculate the number of days between date1 and date2, you can use either Day of year ("y") or Day ("d"). When interval is Weekday ("w"), DateDiff returns the number of weeks between the two dates. If date1 falls on a Monday, DateDiff counts the number of Mondays until date2. It counts date2 but not date1. If interval is Week ("ww"), however, the DateDiff function returns the number of calendar weeks between the two dates. It counts the number of Sundays between date1 and date2. DateDiff counts date2 if it falls on a Sunday; but it doesn't count date1, even if it does fall on a Sunday.
If date1 refers to a later point in time than date2, the DateDiff function returns a negative number.
The firstdayofweek argument affects calculations that use the "w" and "ww" interval symbols.
If date1 or date2 is a date literal, the specified year becomes a permanent part of that date. However, if date1 or date2 is enclosed in double quotation marks (" "), and you omit the year, the current year is inserted in your code each time the date1 or date2 expression is evaluated. This makes it possible to write code that can be used in different years.
When comparing December 31 to January 1 of the immediately succeeding year, DateDiff for Year ("yyyy") returns 1 even though only a day has elapsed. |
så denne er måske en model , som du kan bruge
| |
| Kommentar Fra : natmaden |
Dato : 20-12-04 07:35 |
|
HOV !!
Kode Option Explicit
Private Sub Form_Load()
Dim Msg
Dim tid1 As Date
Dim tid2 As Date
Dim tid3 As Date
tid1 = Now
tid2 = "12-24-2004 18:00"
Msg = "Der er: " & DateDiff("d", tid1, tid2) & " dage, eller " & DateDiff("h", tid1, tid2) & " timer til julemaden er klar"
MsgBox Msg
End Sub |
Mvh. Natmaden
| |
| Kommentar Fra : Harlekin |
Dato : 20-12-04 10:17 |
|
natmadens eksempel er fremragende.
( linien
tid1 = Now tid2 = "12-24-2004 18:00"
skal bare splittes op i 2 linier:
tid1 = Now
tid2 = "12-24-2004 18:00"
men det er nok kandu der har skubbet linien )
| |
| Kommentar Fra : natmaden |
Dato : 20-12-04 12:10 |
|
jeps !
Jeg så det ikke selv men der mangler et linieskift,
og tid3 var tiltænkt til et resultat.
tak Harlekin
Eksemblet regner kun i hele dage og hele timer, men crha jeg regner med at du selv kan bygge videre,
i dit eget spårgsmål bruger du jo 2 timer og 17 min.
Så et svar i minutter er nok bedst.
DateDiff("n", tid1, tid2) giver tiden i hele minutter. oprundet(vist nok)
| |
| Kommentar Fra : natmaden |
Dato : 21-12-04 00:45 |
|
det er jo godt !
VB har god hjælp, du lader cursoren stå på funktionen du vil vide noget om, og trykker F1.
ps. jeg er ikke sikker på om tidsfunktionerne regner med skudår. og negative tider kan også drille.(op/nedrunding)
| |
| Du har følgende muligheder | |
|
Eftersom du ikke er logget ind i systemet, kan du ikke skrive et indlæg til dette spørgsmål.
Hvis du ikke allerede er registreret, kan du gratis blive medlem, ved at trykke på "Bliv medlem" ude i menuen.
| |
|
|