This means that the DateTime object is implicitly initialised to UTC, which is fine for server internal tasks that just want to track elapsed time. However, the technique described here is initialising the DateTime object using microtime() which returns the number of seconds elapsed since the Unix Epoch ( 00:00:00 GMT). Normally the createFromFormat() method will use the local time zone if one is not specified. $now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', '')) Ī note on time zones in response to DaVe. Too bad it doesn't feel quite as elegant any more. Thanks goes to giggsey for pointing out a flaw in my original answer, adding number_format() to the line should fix the case of the exact second. This produces the following output: 04-13-2015 05:56:22.082300įrom the PHP manual page for date formats: $now = DateTime::createFromFormat('U.u', microtime(true)) JavaScript does not support leap seconds.You can readily do this this with the input format U.u. Some browsers use the current DST (Daylight Saving Time) rules for all dates in history. Please note: All tools on this page are based on the date & time settings of your computer and use JavaScript to convert times. More date related programming examples: What's the current week number? - What's the current day number? Thanks to everyone who sent me corrections and updates! Works for Windows PowerShell v1 and v2Ĭommand line: perl -e "print scalar(localtime( epoch))" (If Perl is installed) Replace 'localtime' with 'gmtime' for GMT/UTC time. Math.floor(new Date().getTime()/1000.0) The getTime method returns the time in milliseconds.ĭATETIME() -, then use: get-epochDate 1520000000. SELECT dbinfo('utc_current') FROM sysmaster:sysdual SELECT (CAST(SYS_EXTRACT_UTC(SYSTIMESTAMP) AS DATE) - TO_DATE('','DD/MM/YYYY')) * 24 * 60 * 60 FROM DUAL SELECT unix_timestamp(now()) More MySQL examples
(version 18+), older versions: calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600. timeIntervalSince1970] (returns double) or NSString *currentTimestamp = timeIntervalSince1970]] ĭouble now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() Įpoch := DateTimetoUnix(Now) Tested in Delphi 2010.Įrlang:system_time(seconds). Long epoch = System.currentTimeMillis()/1000 Returns epoch in seconds.ĭ() (.NET Framework 4.6+/.NET Core), older versions: var epoch = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds