unix-timestamp

Unix time and leap seconds

非 Y 不嫁゛ 提交于 2019-11-26 22:44:05
Regarding Unix (POSIX) time, Wikipedia says: Due to its handling of leap seconds, it is neither a linear representation of time nor a true representation of UTC. But the Unix date command does not seem to be aware of them actually $ date -d '@867715199' --utc Mon Jun 30 23:59:59 UTC 1997 $ date -d '@867715200' --utc Tue Jul 1 00:00:00 UTC 1997 While there should be a leap second there at Mon Jun 30 23:59:60 UTC 1997 . Does this mean that only the date command ignores leap seconds, while the concept of Unix time doesn't? Thomas Jung The number of seconds per day are fixed with Unix timestamps .

How to convert a String to long in javascript?

巧了我就是萌 提交于 2019-11-26 22:37:54
问题 I have a millisecond timestamp that I need to convert from a String to long. Javascript has a parseInt but not a parseLong . So how can I do this? Thanks Edit: To expand on my question slightly: given that apparently javascript doesn't have a long type, how can I do simple arithmetic with longs that are initially expressed as strings? E.g subtract one from the other to get a time delta? 回答1: JavaScript has a Number type which is a 64 bit floating point number*. If you're looking to convert a

Convert Unix timestamp to a date string

限于喜欢 提交于 2019-11-26 22:30:08
问题 Is there a quick, one-liner way to convert a Unix timestamp to a date from the Unix command line? date might work, except it's rather awkward to specify each element (month, day, year, hour, etc.), and I can't figure out how to get it to work properly. It seems like there might be an easier way - am I missing something? 回答1: With GNU's date you can do: date -d "@$TIMESTAMP" # date -d @0 Wed Dec 31 19:00:00 EST 1969 (From: BASH: Convert Unix Timestamp to a Date) On OS X, use date -r . date -r

How to get Unix timestamp in php based on timezone

删除回忆录丶 提交于 2019-11-26 20:25:07
问题 Code first echo time() . '<br/>'; echo date('Y-m-d H:i:s') . '<br/>'; date_default_timezone_set('America/New_York'); echo time() . '<br/>'; print_r($timezones[$timezone] . '<br/>'); echo date('Y-m-d H:i:s') . '<br/>'; In the above code the date is printed according to timezone but unix timestamp is same even after setting default timezone How can we print unix timestamp according to timezone? 回答1: The answer provided by Volkerk (that says timestamps are meant to be always UTC based) is

django Datefield to Unix timestamp

寵の児 提交于 2019-11-26 19:43:15
问题 In a model I have a such field: mydate = models.DateField() now a javascript graph function requires unix timestamp such as "1196550000000", how can I return the unix timestamp of my mydate input. Thanks 回答1: edit: please check the second answer, it has a much better solution In python code, you can do this to convert a date or datetime to the Unix Epoch import time epoch = int(time.mktime(mydate.timetuple())*1000) This doesn't work in a Django template though, so you need a custom filter, e

Convert Unixtime to Datetime SQL (Oracle)

独自空忆成欢 提交于 2019-11-26 19:09:38
I have a datetime field(P_DT) and I would like to return all results where P_DT is greater then an input unix timestamp. Does Oracle have any built in functions that can help? In my searchs I find resuts for DateTime to Unix but no Unix to DateTime... There are no built-in functions. But it's relatively easy to write one. Since a Unix timestamp is the number of seconds since January 1, 1970 CREATE OR REPLACE FUNCTION unix_ts_to_date( p_unix_ts IN NUMBER ) RETURN DATE IS l_date DATE; BEGIN l_date := date '1970-01-01' + p_unix_ts/60/60/24; RETURN l_date; END; which you can see being called SQL>

Convert Unix timestamp into human readable date using MySQL

微笑、不失礼 提交于 2019-11-26 18:26:18
Is there a MySQL function which can be used to convert a Unix timestamp into a human readable date? I have one field where I save Unix times and now I want to add another field for human readable dates. CristiC Use FROM_UNIXTIME() : SELECT FROM_UNIXTIME(timestamp) FROM your_table; See also: MySQL documentation on FROM_UNIXTIME() . User What's missing from the other answers (as of this writing) and not directly obvious is that from_unixtime can take a second parameter to specify the format like so: SELECT from_unixtime(timestamp, '%Y %D %M %H:%i:%s') FROM your_table I think what you're looking

Python Create unix timestamp five minutes in the future

佐手、 提交于 2019-11-26 18:03:29
I have to create an "Expires" value 5 minutes in the future, but I have to supply it in UNIX Timestamp format. I have this so far, but it seems like a hack. def expires(): '''return a UNIX style timestamp representing 5 minutes from now''' epoch = datetime.datetime(1970, 1, 1) seconds_in_a_day = 60 * 60 * 24 five_minutes = datetime.timedelta(seconds=5*60) five_minutes_from_now = datetime.datetime.now() + five_minutes since_epoch = five_minutes_from_now - epoch return since_epoch.days * seconds_in_a_day + since_epoch.seconds Is there a module or function that does the timestamp conversion for

Check whether the string is a unix timestamp

冷暖自知 提交于 2019-11-26 17:35:32
I have a string and I need to find out whether it is a unix timestamp or not, how can I do that effectively? I found this thread via Google, but it doesn't come up with a very solid answer, I'm afraid. (And yes, I cribbed the question from the original poster on the aforementioned thread). Gordon Ok, after fiddling with this for some time, I withdraw the solution with date('U') and suggest to use this one instead: function isValidTimeStamp($timestamp) { return ((string) (int) $timestamp === $timestamp) && ($timestamp <= PHP_INT_MAX) && ($timestamp >= ~PHP_INT_MAX); } This check will only

How can I work with dates before 1900 in PHP?

戏子无情 提交于 2019-11-26 17:23:57
问题 I am using PHP and jQuery to build an interactive timeline which needs to display dates between 1500 and 2020. I usually use PHP's strtotime function when working with dates, but it does not work for dates pre-1900. The dates will come from a MySQL database, and are formatted as strings such as " January 31, 1654 " (this may not be the ideal format, but I can't change how they are stored). I am using PHP to parse the dates, basically converting them into pixel values which determine where