• Welcome to Jose's Read Only Forum 2023.
 

(solved) How can i get a time and date from these numbers? 1434014220 etc.S

Started by Theo Gottwald, June 11, 2015, 05:32:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

The following three numbers should calculate to a date/timestamp from today (11.06.2015)
I imagine they could depend on a number-system that has an origin at the 01-01-1970 but that is just an idea.

1434014220
1434013303
1434021234

How can i decode these numbers to a readyble date/time in Powerbasic?
I have tried some "date-to-number versions, but nothing seemed to work.

Pierre Bellisle

Hi Theo,
One way...


'How To Convert a UNIX 'time_t' to a Microsoft Windows time
'https://support.microsoft.com/en-us/kb/167296

'Unix time  - https://en.wikipedia.org/wiki/Unix_time

#COMPILE EXE '#CC 4.04#
#INCLUDE "Win32Api.inc"

%NanoSecFrom1601To1970 = 116444736000000000 'Nanoseconds from 1601-01-01 to 1970-01-01
%TenMillions           = 10000000

'Also see MS function RtlTimeToSecondsSince1970 and RtlSecondsSince1970ToTime
'______________________________________________________________________________

FUNCTION TimeUnixToWin(BYVAL SecondSince1970 AS DWORD)AS STRING
LOCAL File_Time AS QUAD
LOCAL Sys_Time  AS SystemTime

'Under UNIX platforms, file times are in 'time_t' type,
'which represents seconds count since 1970-01-01 UTC, not counting leap seconds.

'Under Win32 platforms, file times are maintained primarily
'in the form of a 64-bit FILETIME structure, which represents
'the number of 100-nanosecond intervals since 1601-01-01 UTC.

'1 second = 1,000,000,000 nanosecond
'Windows FILETIME resolution: 100 nanoseconds = 0.0000001 second = 1 second / 10 millions
'Unix    time_t   resolution: 1 second (Not counting leap one)

File_Time = %NanoSecFrom1601To1970 + SecondSince1970 * %TenMillions
FileTimeToSystemTime(BYVAL VARPTR(File_Time), Sys_Time)

FUNCTION = _
   FORMAT$(Sys_Time.wyear, "0000") & "/" & FORMAT$(Sys_Time.wMonth,  "00") & "/" & _
   FORMAT$(Sys_Time.wDay,    "00") & " " & FORMAT$(Sys_Time.wHour,   "00") & ":" & _
   FORMAT$(Sys_Time.wMinute, "00") & ":" & FORMAT$(Sys_Time.wSecond, "00") & "." & _
   FORMAT$(Sys_Time.wMilliSeconds, "000") & " (Day: " & _
   CHOOSE$(Sys_Time.wDayOfWeek + 1, "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday") & _
   ", month: " & _
   CHOOSE$(Sys_Time.wMonth, "january", "february", "march", "april", "may", "june", _
                            "july", "august", "september", "october", "november", "december") & ")"
END FUNCTION
'______________________________________________________________________________

FUNCTION UnixNow()AS QUAD
LOCAL SysTimeNow  AS SystemTime
LOCAL FileTimeNow AS QUAD

GetLocalTime(SysTimeNow)
SystemTimeToFileTime(SysTimeNow, BYVAL VARPTR(FileTimeNow))

FUNCTION = (FileTimeNow - %NanoSecFrom1601To1970) \ %TenMillions '116,444,736,000,000,000 = 1970/01/01 00:00:00

END FUNCTION
'______________________________________________________________________________

FUNCTION PBMAIN() AS LONG

PRINT "Now: " & TimeUnixToWin(UnixNow)
PRINT "     " & TimeUnixToWin(1434014220)
PRINT "     " & TimeUnixToWin(1434013303)
PRINT "     " & TimeUnixToWin(1434021234)

MOUSE ON : MOUSE 3, UP : WAITKEY$

END  FUNCTION
'______________________________________________________________________________
'

Theo Gottwald


Pierre Bellisle

I'm glad to help...

I did a little cleanup of the above code...

Pierre