Author Topic: Date Formats - (Rosetta)  (Read 2575 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Date Formats - (Rosetta)
« on: June 28, 2012, 03:39:12 AM »
A Mini API for date and time.

Code: OxygenBasic
  1. extern lib "kernel32.dll"
  2.  
  3. typedef struct _SYSTEMTIME {
  4.   WORD wYear;
  5.   WORD wMonth;
  6.   WORD wDayOfWeek;
  7.   WORD wDay;
  8.   WORD wHour;
  9.   WORD wMinute;
  10.   WORD wSecond;
  11.   WORD wMilliseconds;
  12. } SYSTEMTIME, *PSYSTEMTIME;
  13.  
  14. void GetSystemTime(SYSTEMTIME*t);
  15. void GetLocalTime(SYSTEMTIME*t);
  16.  
  17. end extern
  18.  
  19. SYSTEMTIME t
  20. 'GetSystemTime t 'GMT (Greenwich Mean Time)
  21. GetLocalTime t
  22.  
  23. String WeekDay[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
  24. String MonthName[12]={"January","February","March","April","May","June","July","August","September","October","November","December"}
  25. String month=str t.wMonth : if len(month)<2 then month="0"+month
  26. String day=str t.wDay : if len(day)<2 then day="0"+day
  27. '
  28. print "" t.wYear "-" month "-" day
  29. print WeekDay[t.wDayOfWeek+1 and 7 ] " " MonthName[t.wMonth and 31] " " t.wDay " " t.wYear
  30.  

There is a glitch have to fix on word (2 byte) members. They can be corrupted by higher bits, so I have used 'and' bit masks here in the critical places.

http://rosettacode.org/wiki/Date_format#OxygenBasic

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx


Charles