unix-timestamp

mongodb: extract timestamp from ObjectID in json query

荒凉一梦 提交于 2019-11-30 22:16:22
I want to extract the timestamp from my ObjectID with a json query, as I would like to use mongodump but only dump data between certain dates. I dont wanna put my timestamps somewhere else than the ObjectID as I need the database to be as small as possible. Is there a way to to exstract the timestamp from ObjectID with a simple json query that mongodump accepts? You can do this fairly simply, at doc page Mongo Extended JSON (which is quite well hidden) you can find a table describing how to represent mongo extended datatypes in JSON. As you probably know, the first 4 bytes of ObjectId

dateWithTimeIntervalSince1970 not returning correct date

僤鯓⒐⒋嵵緔 提交于 2019-11-30 21:40:18
I have the following method below that is meant to retrieve and convert a unixTimeStamp from an API call to a NSDate object that I can easily manipulate and use. For some reason, this returns wrong values. An example would be when the unixTimeStamp is 1385152832, the date SHOULD be Fri, 22 Nov 2013 20:40:31 GMT November 22, 2013 at 3:40:31 PM EST but instead spits out: 45852-09-07 08:13:52 EST. Does anyone know why this would happen? -(NSDate *)messageDate { NSTimeInterval unixTimeStamp = [[self messageDateString] doubleValue]; NSDate *messageDate = [NSDate dateWithTimeIntervalSince1970

Formatting Unix timestamp with ctime in c

余生长醉 提交于 2019-11-30 20:33:18
I'm trying to format a 10-digit Unix time stamp (currently a string) using ctime. However, ctime() expects a parameter of type time_t, not a string. What must I do before I can use ctime? In other words, can I easily convert the string into a time_t? You're saying you have something like 1346426869 as a string and want it to be a time_t? time_t raw_time = atoi("1346426869"); printf("current time is %s",ctime(&raw_time)); > current time is Fri Aug 31 11:27:49 2012 The time_t type is just an integer. It is the number of seconds since the Epoch. You'll need to parse the string first. Start here:

How to get the day of the week from a Unix timestamp (PHP)?

为君一笑 提交于 2019-11-30 18:34:30
How do I get the day (1-7) from a Unix timestamp in PHP? I also need the day date (1-31) and month (1-12). You can use date() function $weekday = date('N', $timestamp); // 1-7 $month = date('m', $timestamp); // 1-12 $day = date('d', $timestamp); // 1-31 see http://docs.php.net/getdate e.g. $ts = time(); // could be any timestamp $d=getdate($ts); echo 'day of the week: ', $d['wday'], "\n"; echo 'day of the month: ', $d['mday'], "\n"; echo 'month: ', $d['mon'], "\n"; It's the date() function you're after. You can get more details from the PHP manual but in a nutshell here are the functions you

PHP-MYSQL: Converting Unix Timestamp to DateTime and vice versa

。_饼干妹妹 提交于 2019-11-30 14:33:45
问题 im using php 5.4.6 and MySQL 5.5.29 and I get trouble by converting a UNIX TIMESTAMP to MYSQL DATETIME and vice versa. Mysql and php wun on the same local machine. I have a simple mysql table CREATE TABLE Entry( id SERIAL PRIMARY KEY, created DATETIME NOT NULL); To insert data I use php PDO and mysql NOW(). This works fine, the correct datetime is stored in the database. My plan is to work with unix timestamps on client side (php & mysql on server side). So I would like to deliver unix

MYSQL query between two timestamps

妖精的绣舞 提交于 2019-11-30 12:37:17
问题 I have the following entry in my DB table eventName(varchar 100) -> myEvent date(timestamp) -> 2013-03-26 09:00:00 and I am trying to use the following query; SELECT * FROM eventList WHERE `date` BETWEEN UNIX_TIMESTAMP(1364256001) AND UNIX_TIMESTAMP(1364342399) i.e between 2013-03-26 00:00:01 and 2013-03-26 23:59:59 but it is giving me 0 results. I have tried expanding the date range with no luck and there are definitely results within the range. any help is appreciated. 回答1: Try: SELECT *

Convert std::chrono::time_point to unix timestamp

笑着哭i 提交于 2019-11-30 11:51:12
问题 How can I get an std::chrono::duration since a fixed date? I need this to convert a std::chrono::time_point to an unix timestamp. Insert code into XXX auto unix_epoch_start = XXX; auto time = std::chrono::system_clock::now(); auto delta = time - unix_epoc_start; auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(delta).count(); I know time_point has a method time_since_epoch() but it's not guaranteed that this is the same as the unix epoch (00:00:00 UTC on 1 January 1970).

PHP strtotime() function wrong by 1 hour?

。_饼干妹妹 提交于 2019-11-30 11:36:42
I am converting dates and times into timestamps using PHP before they are inserted into my MySQL database. My problem is that when i use PHP's strtotime function the output timestamp is -1 hour behind my actual time. For example, considering todays date: 07/21/2010. When i use php code like: <?php $my_timestamp = strtotime("07/21/2010"); echo $my_timestamp; ?> The timestamp sent back is the GMT equivilent MINUS 1 hour. i.e. i get back: 20 Jul 2010 23:00:00 GMT instead of 21 Jul 2010 00:00:00 GMT. I live in the UK so my timezone is GMT. I have declared my timezone in the script using date

PHP-MYSQL: Converting Unix Timestamp to DateTime and vice versa

邮差的信 提交于 2019-11-30 10:56:06
im using php 5.4.6 and MySQL 5.5.29 and I get trouble by converting a UNIX TIMESTAMP to MYSQL DATETIME and vice versa. Mysql and php wun on the same local machine. I have a simple mysql table CREATE TABLE Entry( id SERIAL PRIMARY KEY, created DATETIME NOT NULL); To insert data I use php PDO and mysql NOW(). This works fine, the correct datetime is stored in the database. My plan is to work with unix timestamps on client side (php & mysql on server side). So I would like to deliver unix timestamps to my client. Therefore I use MySql UNIX_TIMESTAMP() function to convert it directly in the query.

How to convert date time into unix epoch value in Postgres?

帅比萌擦擦* 提交于 2019-11-30 10:53:45
How do I convert the following format to UNIX timestamps? A value like: 01-02-2015 10:20 PM should be converted to: 1418273999000 I did try to_timestamp function but its not working for me. If your data is stored in a column called ts, in a table called data, do this: select extract(epoch from ts) from data To add Joe's answer, you can use date_part , i think it's syntax is clearer than 'extract'. select date_part('epoch', ts) from data; 来源: https://stackoverflow.com/questions/27740363/how-to-convert-date-time-into-unix-epoch-value-in-postgres