How do I extract the created date out of a Mongo ObjectID

getTimestamp() The function you need is this one, it’s included for you already in the shell: ObjectId.prototype.getTimestamp = function() { return new Date(parseInt(this.toString().slice(0,8), 16)*1000); } References Check out this section from the docs: Extract insertion times from _id rather than having a separate timestamp field This unit test also demostrates the same: mongo / jstests … Read more

Convert unix timestamp to date in java [duplicate]

You can use SimlpeDateFormat to format your date like this: long unixSeconds = 1372339860; // convert seconds to milliseconds Date date = new java.util.Date(unixSeconds*1000L); // the format of your date SimpleDateFormat sdf = new java.text.SimpleDateFormat(“yyyy-MM-dd HH:mm:ss z”); // give a timezone reference for formatting (see comment at the bottom) sdf.setTimeZone(java.util.TimeZone.getTimeZone(“GMT-4”)); String formattedDate = sdf.format(date); System.out.println(formattedDate); … Read more

How should unix timestamps be stored in int columns?

Standard UNIX timestamps are a signed 32bit integer, which in MySQL is a regular “int” column. There’s no way you could store 9,999,999,999, as that’s way outside the representation range – the highest a 32bit int of any sort can go is 4,294,967,295. The highest a signed 32bit in goes is 2,147,483,647. If/when UNIX timestamps … Read more

Converting unix time into date-time via excel

To convert the epoch(Unix-Time) to regular time like for the below timestamp Ex: 1517577336206 First convert the value with the following function like below =LEFT(A1,10) & “.” & RIGHT(A1,3) The output will be like below Ex: 1517577336.206 Now Add the formula like below =(((B1/60)/60)/24)+DATE(1970,1,1) Now format the cell like below or required format(Custom format) m/d/yyyy … Read more

Convert python datetime to timestamp in milliseconds

In Python 3 this can be done in 2 steps: Convert timestring to datetime object Multiply the timestamp of the datetime object by 1000 to convert it to milliseconds. For example like this: from datetime import datetime dt_obj = datetime.strptime(‘20.12.2016 09:38:42,76’, ‘%d.%m.%Y %H:%M:%S,%f’) millisec = dt_obj.timestamp() * 1000 print(millisec) Output: 1482223122760.0 strptime accepts your timestring … Read more

Check whether the string is a unix timestamp

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 return true if the given $timestamp is a string and consists solely … Read more

Get current NSDate in timestamp format

Here’s what I use: NSString * timestamp = [NSString stringWithFormat:@”%f”,[[NSDate date] timeIntervalSince1970] * 1000]; (times 1000 for milliseconds, otherwise, take that out) If You’re using it all the time, it might be nice to declare a macro #define TimeStamp [NSString stringWithFormat:@”%f”,[[NSDate date] timeIntervalSince1970] * 1000] Then Call it like this: NSString * timestamp = TimeStamp; … Read more