Auf Console unter Windows geht date -u nicht.
Mit der Win-API kann zwischen Lokaler und System- Zeit unterschieden werden.
Ich hatte da mal was vorbereitet.
Code: Alles auswählen
Procedure.s GetDateStr(*tm.SYSTEMTIME=0, Format$="dddd',' dd'.' MMMM'.' yyyy") ;' long version -- see MSDN for further date formats (no time)
Protected result$, DateStr${32}, cch ;' MSDN: For example, to get the date string "Wed, Aug 31 94",
;' ;' the application uses the picture string "ddd',' MMM dd yy".
cch = GetDateFormat_(#LOCALE_USER_DEFAULT, 0, *tm, Format$, @DateStr$, 32) ;' *tm = 0 .. use the current locale system date
If cch
result$ = Left(DateStr$, cch)
Else
;Debug GetLastError() ;' my own function with FormatMessage and so on
EndIf
ProcedureReturn result$
EndProcedure ;()
Procedure.s GetTimeStr(*tm.SYSTEMTIME=0, Format$="HH':'mm':'ss") ;' hh .. 12 hours, HH .. 24 hours
;
; int GetTimeFormat(LCID Locale, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCTSTR lpFormat, LPTSTR lpTimeStr, int cchTime);
;
; dwFlags -- remarks
; #TIME_NOMINUTESORSECONDS ;' Do Not use minutes Or seconds.
; #TIME_NOSECONDS ;' Do Not use seconds.
; #TIME_NOTIMEMARKER ;' Do Not use a time marker.
; #TIME_FORCE24HOURFORMAT ;' Always use a 24-hour time format.
;
; Picture Meaning
; h Hours with no leading zero for single-digit hours; 12-hour clock
; hh Hours with leading zero for single-digit hours; 12-hour clock
; H Hours with no leading zero for single-digit hours; 24-hour clock
; HH Hours with leading zero for single-digit hours; 24-hour clock
; m Minutes with no leading zero for single-digit minutes
; mm Minutes with leading zero for single-digit minutes
; s Seconds with no leading zero for single-digit seconds
; ss Seconds with leading zero for single-digit seconds
; t One character time marker string, such as A or P
; tt Multi-character time marker string, such as AM or PM
;
;' i.e. "hh':'mm':'ss tt" --> "11:29:40 PM"
;
Protected result$, TimeStr${12}, cch
cch = GetTimeFormat_(#LOCALE_USER_DEFAULT, 0, *tm, Format$, @TimeStr$, 12)
If cch ;:Debug " cch = " + cch +" --> result = " + TimeStr$, 9
result$ = Left(TimeStr$, cch)
Else
;
EndIf
ProcedureReturn result$
EndProcedure ;()
Global ltm.SYSTEMTIME, stm.SYSTEMTIME
Global tz.TIME_ZONE_INFORMATION
GetLocalTime_(ltm) ;' Retrieves the current system date and time in UTC format.
Debug "Local = " + GetDateStr(ltm) + " -- " + GetTimeStr(ltm)
GetSystemTime_(stm) ;' Retrieves the current system date and time. The system time is expressed in Coordinated Universal Time (UTC).
Debug "System = " + GetDateStr(stm) + " -- " + GetTimeStr(stm)
;
; All translations between UTC and local time are based on the following formula:
; UTC = local time + bias
;
; The bias is the difference, in minutes, between UTC and local time.
;
GetTimeZoneInformation_(tz)
Debug "BIAS = " + tz\Bias
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home