How can I convert a ColdFusion date to Unix Timestamp?
myDate = DateAdd("m", -1, Now());
I would like to convert myDate to unix timestamp using ColdFusion
Thanks
Convert from human-readable date to epochlong epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds. date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.
To find the unix current timestamp use the %s option in the date command. The %s option calculates unix timestamp by finding the number of seconds between the current date and unix epoch.
In a computing context, an epoch is the date and time relative to which a computer's clock and timestamp values are determined. The epoch traditionally corresponds to 0 hours, 0 minutes, and 0 seconds (00:00:00) Coordinated Universal Time (UTC) on a specific date, which varies from system to system.
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
Just create the UNIX origin date, and do a DateDiff from then to now (or whatever your date variable is) in seconds.
<cfset startDate = createdatetime( '1970','01','01','00','00','00' )>
<cfset datetimeNow = dateConvert( "local2Utc", now() )>
<cfset UnixStamp = datediff( 's', startdate, datetimeNow )>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With