Page 1 of 1

Unix timestamp

Posted: 04 Nov 2020, 03:30
by c7aesa7r
How do i convert this timestamp to a date format, like 2020-04-11, etc

Code: Select all

1604478439708
Also, convert today date to this timestamp format?

I think the format is: year/month/day/hour/min/sec/ms

I tried:

Code: Select all

myNow := A_YYYY A_MM A_DD A_Hour A_Min A_Sec A_MSec
x := human2Unix(myNow)
FileAppend, human2unix: %x% `n, *

y := unix2Human(1604478439708)
FileAppend,  unix2Human: %y% `n, *
return

unix2Human(unixTimestamp) {
	returnDate = 19700101000000
	returnDate += unixTimestamp, s
	return returnDate
}
human2Unix(humanTime) {
	humanTime -= 1970, s
	return humanTime
}
But x is not returning the same format on the value, i think it's not including the ms
And y does not output anything.

Re: Unix timestamp

Posted: 04 Nov 2020, 04:16
by hd0202

Code: Select all

unix2Human(unixTimestamp) {
	returnDate = 19700101000000
	returnDate += unixTimestamp//1000, s
	return returnDate
}
Hubert

Re: Unix timestamp

Posted: 04 Nov 2020, 04:23
by c7aesa7r
Ty, and to convert this timestamp with ms to date format like 2020-11-04 etc

Re: Unix timestamp

Posted: 04 Nov 2020, 11:31
by hd0202

Code: Select all

unix2Human(unixTimestamp) {
	rDate = 19700101000000
	rDate += unixTimestamp//1000, s
	msec := mod(unixTimestamp, 1000)
	formattime, returnDate, rDate, yyyy-MM-dd 
	return returnDate " etc, msec: " msec
}
Hubert