Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PureBasic Adventures - Calendar Date Format

Featured Replies

Posted

This is a repost from the "PureBasic Adventures" blog...

A query was raised last week about how to determine the calendar date format for different regions; year/month/day, day/month/year, etc. After a bit of fruitless pondering whether this could be achieved via API I decided to see if it could be done via the registry. Multiple editions of Windows support the International registry subkey and from there we can use either sShortDate or sLongDate to help us reach our goal. The operating system kindly finds and formats the calendar date in the correct regional order when the user configures their region in the Control Panel or during installation. I chose sShortDate and replaced those known registry values with the values retrieved from the SYSTEMTIME structure. Below is the example...

; Setup string and data sizes for storing date values...
  
DateValue.s = Space(20) : DateSize = Len(DateValue)
  
; Open registry and retrieve the local calendar/date format
  
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "Control Panel\International", #Null, #KEY_READ, @DateFormat) = #ERROR_SUCCESS  
  If RegQueryValueEx_(DateFormat, "sShortDate", #Null, #Null, @DateValue, @DateSize) = #ERROR_SUCCESS

    ; Receive the local date

    GetLocalTime_(@lpSystemTime.SYSTEMTIME)
      
    ; Find registry string values and replace string values from SYSTEMTIME structure

    DateValue = ReplaceString(DateValue, "yyyy", Str(lpSystemTime\wYear))
    DateValue = ReplaceString(DateValue, "yy", Str(lpSystemTime\wYear))
    DateValue = ReplaceString(DateValue, "MM", Str(lpSystemTime\wMonth))
    DateValue = ReplaceString(DateValue, "M", Str(lpSystemTime\wMonth))
    DateValue = ReplaceString(DateValue, "dd", Str(lpSystemTime\wDay))
    DateValue = ReplaceString(DateValue, "d", Str(lpSystemTime\wDay))
      
    ; Display the date
      
    MessageBox_(#Null, DateValue, "What is the date today?", #MB_ICONQUESTION | #MB_TOPMOST | #MB_SETFOREGROUND)
  EndIf
    
  RegCloseKey_(DateFormat)
EndIf

If you know of a way this can be done purely by API please let me know...

Ted.

Todays Date.zip

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.