Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ColdFusion Date to Unix timestamp

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

like image 639
myTest532 myTest532 Avatar asked Aug 19 '19 17:08

myTest532 myTest532


People also ask

How do you convert date to epoch time?

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.

How do you find time in Unix?

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.

What is epoch time format?

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.

How do you read epoch time?

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).


Video Answer


1 Answers

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 )>
like image 90
TRose Avatar answered Oct 05 '22 05:10

TRose