Jump to content

Date manipulation: Difference between revisions

m (added a ;Task: (bold) header.)
Line 1,709:
domingo, 08 de marzo de 2009 13:30:00
domingo, 08 de marzo de 2009 23:30:00</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>
EnableExplicit
 
Procedure.i ToPBDate(Date$, *zone.String)
Protected year, month, day, hour, minute
Protected month$, temp$, time$, pm$, zone$
month$ = StringField(date$, 1, " ")
day = Val(StringField(date$, 2, " "))
year = Val(StringField(date$, 3, " "))
time$ = StringField(date$, 4, " ")
zone$ = StringField(date$, 5, " ")
Select month$
Case "January" : month = 1
Case "February" : month = 2
Case "March" : month = 3
Case "April" : month = 4
Case "May" : month = 5
Case "June" : month = 6
Case "July" : month = 7
Case "August" : month = 8
Case "September" : month = 9
Case "October" : month = 10
Case "November" : month = 11
Case "December" : month = 12
EndSelect
hour = Val(StringField(time$, 1, ":"))
temp$ = StringField(time$, 2, ":")
minute = Val(Left(temp$, 2))
pm$ = Right(temp$, 2)
If pm$ = "am"
If hour = 12 : hour = 0 : EndIf
Else
If hour <> 12 : hour + 12 : EndIf
EndIf
*zone\s = zone$
ProcedureReturn Date(year, month, day, hour, minute, 0)
EndProcedure
 
Procedure.s FromPBDate(Date, zone$)
Protected year$ = Str(Year(Date))
Protected month = Month(Date)
Protected day$ = Str(Day(Date))
Protected hour = Hour(Date)
Protected minute = Minute(Date)
Protected month$, time$, pm$, result$
Select month
Case 1 : month$ = "January"
Case 2 : month$ = "February"
Case 3 : month$ = "March"
Case 4 : month$ = "April"
Case 5 : month$ = "May"
Case 6 : month$ = "June"
Case 7 : month$ = "July"
Case 8 : month$ = "August"
Case 9 : month$ = "September"
Case 10 : month$ = "October"
Case 11 : month$ = "November"
Case 12 : month$ = "December"
EndSelect
If hour > 12
hour - 12
pm$ = "pm"
ElseIf hour = 12
pm$ = "pm"
Else
If hour = 0 : hour = 12 : EndIf
pm$ = "am"
EndIf
time$ = Str(hour) + ":" + RSet(Str(minute), 2, "0") + pm$
result$ = month$ + " " + day$ + " " + year$ + " " + time$ + " " + zone$
ProcedureReturn result$
EndProcedure
Define date
Define date1$, date2$
Define zone.String
 
If OpenConsole()
date1$ = "March 7 2009 7:30pm EST"
PrintN("Starting date/time : " + date1$)
date = ToPBDate(date1$, @zone)
date = AddDate(date, #PB_Date_Hour, 12); add 12 hours
date2$ = FromPBDate(date, zone\s)
PrintN("12 hours later : " + date2$)
date = AddDate(date, #PB_Date_Hour, 5); adjust to GMT
date2$ = FromPBDate(date, "GMT")
PrintN("Or in GMT timezone : " + date2$)
PrintN("")
PrintN("Press any key to close the console")
Repeat: Delay(10) : Until Inkey() <> ""
CloseConsole()
EndIf
</lang>
 
{{out}}
<pre>
Starting date/time : March 7 2009 7:30pm EST
12 hours later : March 8 2009 7:30am EST
Or in GMT timezone : March 8 2009 12:30pm GMT
</pre>
 
=={{header|Python}}==
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.