Set System Date and Time - Windows

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Set System Date and Time - Windows

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by wayne1.

Code: Select all

;wYear 
;Specifies the current year. 
;wMonth 
;Specifies the current month; January = 1, February = 2, and so on. 
;wDayOfWeek 
;Specifies the current day of the week; Sunday = 0, Monday = 1, and so on. 
;wDay 
;Specifies the current day of the month. 
;wHour 
;Specifies the current hour. 
;wMinute 
;Specifies the current minute. 
;wSecond 
;Specifies the current second. 
;wMilliseconds 
;Specifies the current millisecond. 

;The wDayOfWeek member of the Time Structure is ignored. 

  
Structure Time 
  wYear.w ; 
  wMonth.w ; 
  wDayOfWeek.w ; 
  wDay.w ; 
  wHour.w ; 
  wMinute.w ; 
  wSecond.w ; 
  wMilliseconds.w ; 
EndStructure

Dim SetTime.Time(0)
SetTime(0)\wYear = 1993
SetTime(0)\wMonth=1 
;SetTime(0)\wDayOfWeek=0 
SetTime(0)\wDay=8 ;I dont know why but day of the month starts at 2 instead of one (on mine anyway)
SetTime(0)\wHour=2 ; (UTC)
SetTime(0)\wMinute=23
SetTime(0)\wSecond=12
SetTime(0)\wMilliseconds=3

Result = MessageRequester("New Date and Time", "Allow program to reset date and time to " + Str(SetTime(0)\wMonth) + "\"+ Str(SetTime(0)\wDay - 1)+ " \"+ Str(SetTime(0)\wYear) + "?", #PB_MessageRequester_YesNo)

If Result = #PB_MessageRequester_Yes
  SetSystemTime_(SetTime(0));
  Result = MessageRequester("New Date and Time", "Date  was reset to " +  Str(SetTime(0)\wMonth) + "\"+ Str(SetTime(0)\wDay - 1)+ " \"+ Str(SetTime(0)\wYear) + " the time was also reset",0)
Endif








Edited by - wayne1 on 10 July 2001 04:06:53
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

You can use the Windows Structure SYSTEMTIME like:

Code: Select all

SetTime.SYSTEMTIME ; (all values UTC = Greenwich date & time)
SetTime\wYear = 2001
SetTime\wMonth=11 
;SetTime\wDayOfWeek=0 
SetTime\wDay=4
SetTime\wHour=2
SetTime\wMinute=23
SetTime\wSecond=12
SetTime\wMilliseconds=3

SetSystemTime_(SetTime);

Result = MessageRequester("New Date and Time", "Date is set to " + str(SetTime\wMonth) + "\"+ str(SetTime\wDay)+ " \"+ str(SetTime\wYear) + " the time is also set",0) 
You will always set the Greewich time and date!

Thats why:
SetTime(0)\wDay=8 ;I dont know why but day of the month starts at 2 instead of one (on mine anyway)
But it depends where yuo live...




Have a nice day...
Franco
Post Reply