Convert back GetDateTimeString()
Moderator: POL Developer
Convert back GetDateTimeString()
Someone has a function to convert back to seconds from 1970 a string returned by GetDateTimeString(), es. '2011-02-17 23:34:30' ?
Re: Convert back GetDateTimeString()
Nevermind, I just did it.
Code: Select all
// Return the number of seconds from epoch respectfully to the input string.
// Input typically is from GetDateTimeString(), es: '2011-02-17 23:34:30'
// The epoch is January 1, 1970, 00:00:00 GMT.
// This function assure you this:
// var nSystime := polcore().systime + 60*SHARD_TIME_ZONE;
// var sGDTS := GetDateTimeString();
// var nBack := DecodeDateTimeString(sGDTS);
// nBack == nSystime
function DecodeDateTimeString(sString)
var arString := SplitWords(sString);
var arDate := SplitWords(arString[1], "-");
var arTime := SplitWords(arString[2], ":");
var time := 0;
time := CInt(arTime[3])
+ 60 * CInt(arTime[2])
+ 60 * 60 * CInt(arTime[1]);
var nYears := CInt(arDate[1]) - 1970;
var c, nSecsOfYear := 0;
for (c := 1970; c < CInt(arDate[1]); c := c + 1)
nSecsOfYear := nSecsOfYear + DaysInYear(c) * SECONDS_IN_DAY;
endfor
var nSecsOfMonth := GetDaysFromStartYearToMonth(CInt(arDate[2])) * SECONDS_IN_DAY;
// Subtracting 1 because today time is given by the other part of the string.
var nSecsOfDay := (CInt(arDate[3])-1) * SECONDS_IN_DAY;
time := time + nSecsOfYear + nSecsOfMonth + nSecsOfDay;
return time;
endfunction