unix-timestamp

When do we chose DateTime over Timestamp

社会主义新天地 提交于 2019-11-30 09:53:13
As I spend most of my time with php and mysql or pgsql, I will use DateTime as a generic word for the date API. In php there is no "Date", "Time", "DateTime" and "DateTimeOffset" As I develop web application more and more elaborate, I use DateTime most of time, but sometimes I wonder if it is really what I want. for example it happens that I just want to display the today's date (for example when I want to store a forum or blog post), there is no calculation, no filter to provide, no iteration to happen... So why do I use \DateTime over the date() function? I saw this topic that provides some

Best practice for storing the date in MySQL from PHP

半城伤御伤魂 提交于 2019-11-30 08:01:43
I've been using the unix timestamp all my life. I like it because it's easy to compare, it's fast because I store it as an integer. And since I'm using PHP, I can get any date/time format with date() function from the unixtimestamp. Now, some people are saying that it's best to use the DATETIME format. But besides the more suited name, I don't see any advantages. Is it indeed better to use DATETIME, if so, what are the advantages? Thanks. If you store dates as Unix timestamps in the database, you're giving yourself the heavy lifting. You have to convert them to the formats you want to use, you

Date string conversion to unix timestamp in JavaScript / jQuery

大城市里の小女人 提交于 2019-11-30 06:26:00
问题 I have date string in this format: 2009-07-15 00:00:00 - 2009-07-15 08:16:23 Could anyone help me to tweak the date string to unix timestamp into something like this: 1247634000 - 1247663783 I am using GMT-5 Timezone. What JavaScript or jQuery techniques could be used? 回答1: var input = "2009-07-15 00:00:00 - 2009-07-15 08:16:23"; input = input.split(" - ").map(function (date){ return Date.parse(date+"-0500")/1000; }).join(" - "); Demo Date.parse docs Note: This won't work on old browsers

dateWithTimeIntervalSince1970 not returning correct date

我们两清 提交于 2019-11-30 05:24:33
问题 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 = [

Difference between UNIX_TIMESTAMP and NOW() in MySQL

拜拜、爱过 提交于 2019-11-30 05:21:17
I have a blog where users can comment. I insert the time at which they posted a comment using NOW() and then use date('j M Y', stored timestamp) to show the time at which they posted. I want to know does NOW() return the locatime of the end user or the localtime at my server . Is it better suited to use UNIX_TIMESTAMP than NOW() to calculate the localtime at which users posted a comment. The function NOW() generates a formatted date-time string, determined by the time zone of your MySQL server. However, it would be better to store times using UNIX_TIMESTAMP() , which is expressed in GMT. Doing

Formatting Unix timestamp with ctime in c

二次信任 提交于 2019-11-30 05:02:07
问题 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? 回答1: 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 回答2: The time_t type is

When does a UNIX directory change its timestamp

☆樱花仙子☆ 提交于 2019-11-30 04:39:13
I used "touch" on a file, updating the file's timestamp but the parent directory's timestamp did not change. However, (as expected) when I created a new file within the parent directory, the directory's timestamp did change. What criteria do UNIX-like operating systems (specifically AIX) use to determine when to update the timestamp of a directory? The timestamp is updated when the data that represents the directory changes. A change in a subdirectory of directory D does not change anything in the representation of D because D only points to the subdirectory, not to what's inside it. On the

MYSQL query between two timestamps

喜夏-厌秋 提交于 2019-11-30 04:12:41
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. Frank Conry Try: SELECT * FROM eventList WHERE `date` BETWEEN FROM_UNIXTIME(1364256001) AND FROM_UNIXTIME(1364342399) Or

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

 ̄綄美尐妖づ 提交于 2019-11-30 02:48:53
问题 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). 回答1: You can use date() function $weekday = date('N', $timestamp); // 1-7 $month = date('m', $timestamp); // 1-12 $day = date('d', $timestamp); // 1-31 回答2: 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"; 回答3: It's the

Convert std::chrono::time_point to unix timestamp

流过昼夜 提交于 2019-11-30 01:31:01
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). bames53 A unix time stamp is defined as the number of seconds since January 1, 1970 UTC, except not