unix-timestamp

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

别说谁变了你拦得住时间么 提交于 2019-11-28 03:06:01
I'm using the Mongo shell to query my Mongo db. I want to use the timestamp contained in the ObjectID as part of my query and also as a column to extract into output. I have setup Mongo to create ObjectIDs on its own. My problem is I can not find out how to work with the ObjectID to extract its timestamp. Here are the queries I am trying to get working. The 'createdDate' field is a placeholder; not sure what the correct field is: //Find everything created since 1/1/2011 db.myCollection.find({date: {$gt: new Date(2011,1,1)}}); //Find everything and return their createdDates db.myCollection.find

How to convert a 13 digit Unix Timestamp to Date and time?

梦想的初衷 提交于 2019-11-28 02:49:55
问题 I have this 13 digit timestamp 1443852054000 that i want to convert to date and time but dont succeed. I have tried this codes: echo date('Y-m-d h:i:s',$item->timestamp); doesnt work for me and also this $unix_time = date('Ymdhis', strtotime($datetime )); and this : $item = strtotime($txn_row['appoint_date']); <?php echo date("Y-m-d H:i:s", $time); ?> what should i use? 回答1: This timestamp is in milliseconds, not in seconds. Divide it by 1000 and use date function: echo date('Y-m-d h:i:s',

convert date to unixtime php

爱⌒轻易说出口 提交于 2019-11-28 02:48:52
问题 I have a form which posts date information month, day, yeah, hour, minute, am/pm. How do i encode/decode this to and from unixtime using php? 回答1: mktime() - Get Unix timestamp for a date echo mktime(23, 24, 0, 11, 3, 2009); 1257290640 To handle AM/PM just add 12 to hours if PM. mktime($isAM ? $hrs : ($hrs + 12), $mins, $secs, $m, $d, $y); Alternatively you could use strtotime(): strtotime() - Parse about any English textual datetime description into a Unix timestamp echo strtotime("2009-11

How to get Unix timestamp in php based on timezone

拜拜、爱过 提交于 2019-11-27 20:38:51
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? Cecil Zorg The answer provided by Volkerk (that says timestamps are meant to be always UTC based) is correct, but if you really need a workaround (to make timezone based timestamps) look at my example. <

django Datefield to Unix timestamp

Deadly 提交于 2019-11-27 19:00:45
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 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.g: import time from django import template register = template.Library() @register.filter def epoch(value):

Unix time conversions in C# [duplicate]

安稳与你 提交于 2019-11-27 18:59:39
This question already has an answer here: How can I convert a Unix timestamp to DateTime and vice versa? 16 answers I am trying to get the GMT in unix time. I use the following code: public static long GetGMTInMS() { var unixTime = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); return (long)unixTime.TotalMilliseconds; } To then convert the unix time back to a DatTime object, I use this: public static DateTime UnixTimeStampToDateTime(double unixTimeStamp) { System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); dtDateTime = dtDateTime

selecting rows in the last 5 minutes using unix time stamp

可紊 提交于 2019-11-27 18:51:16
问题 Iam trying to figure out whetere data was save to the db in the las 5 minutes. SELECT COUNT(id), DATE_FORMAT(`timestamp`, '%Y-%m-%d %H:%i') FROM `table` WHERE `timestamp` >= CURRENT_TIMESTAMP - INTERVAL 5 MINUTE timestamp is a unix timestamp (millisecs from 1970). doesn't work, I get null num_rows instead of 0 and if I use if (!isset($resultHistory->num_rows) || !$resultHistory->num_rows) to do actions, the code does not enter the loop.. I also tried SELECT COUNT(id), DATE_FORMAT(`timestamp`,

How to convert a String to long in javascript?

江枫思渺然 提交于 2019-11-27 18:04:37
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? JavaScript has a Number type which is a 64 bit floating point number*. If you're looking to convert a string to a number, use either parseInt or parseFloat . If using parseInt , I'd recommend always passing the

Batch: Timestamp to UNIX Time

柔情痞子 提交于 2019-11-27 17:49:18
问题 For all I know, Batch does not have a command that gives the UNIX time. The closest one I can find is %time% , which only displays the timestamp. Is there a command, or set of commands in Batch with which you can get the UNIX time? 回答1: There's Richie Lawrence's batch library that has all those nifty handy scripts. The one you need is DateToSec (which uses GetDate and GetTime). Here's a simplified script, that employs a little WMI: @echo off setlocal call :GetUnixTime UNIX_TIME echo %UNIX

uses for mongodb ObjectId creation time

感情迁移 提交于 2019-11-27 17:26:37
The ObjectId used as the default key in mongodb documents has embedded timestamp (calling objectid.generation_time returns a datetime object). So it is possible to use this generation time instead of keeping a separate creation timestamp? How will you be able to sort by creation time or query for the last N items efficiently using this embedded timestamp? Andrew Orsich I suppose since MongoDB ObjectId contain a timestamp, you can sort by 'created date' if you will sort by objectId: items.find.sort( [['_id', -1]] ) // get all items desc by created date. And if you want last 30 created items you