PK
06/02/2023, 8:55 PMwriteDump( createObject("java", "java.util.Date").init().getTime() );
However, I want to be able to pass it a date to get the epoch time and my efforts are failing. I'm not sure where and in what format to pass it a date.
Thanks.bdw429s
06/02/2023, 9:01 PMfunction dateToGMTEpoch( required date thisDate ) {
// current GMT epoch date
return dateDiff( 's', '1970-01-01 00:00:00', ( dateAdd( 's', ( getTimeZoneInfo( 'pst' ).utcTotalOffset + ( getTimeZoneInfo( 'pst' ).isDSTon ? getTimeZoneInfo( 'pst' ).DSTOffset : 0 ) ), thisDate ) ) );
}
bdw429s
06/02/2023, 9:02 PMpst
timezone infobdw429s
06/02/2023, 9:02 PMbdw429s
06/02/2023, 9:02 PMPK
06/02/2023, 9:11 PMjc
06/02/2023, 9:36 PMfunction getEpoch( required date timestamp ) {
return int( arguments.timestamp.getTime() / 1000 );
}
jc
06/02/2023, 9:41 PMgetTimeZoneInfo
only works on Luceebdw429s
06/02/2023, 10:46 PMbdw429s
06/02/2023, 10:49 PMbdw429s
06/02/2023, 10:49 PMbdw429s
06/02/2023, 10:49 PMbdw429s
06/02/2023, 10:50 PMbdw429s
06/02/2023, 10:50 PMPK
06/02/2023, 11:21 PMseancorfield
java.util.Date
has no TZ itself so it depends on the TZ of the JVM (or the host server if you haven't overridden it). We have all our servers, our JVMs, and our databases all configured to UTC and then we translate to TZ for input/display based on the user's selected TZ (since we're a global company).seancorfield
bkbk
06/10/2023, 9:22 AM<cfscript>
/* Arbitrary date-time in the format MMM dd yyyy HH:mm:ss Z.
My timezone is Central European Summer Time (offset: UTC/GMT +2 hours)*/
dateFormat = createObject("java", "java.text.SimpleDateFormat").init("MMM dd yyyy HH:mm:ss Z");
dateAsString = "Jun 10 2023 11:13:30 +0200";
/* Convert to java.util.Date object */
dateObject = dateFormat.parse(dateAsString);
/* Returns the number of milliseconds */
writeoutput("Milliseconds since January 1, 1970, 00:00:00 GMT = " & dateObject.getTime() );
</cfscript>