unix-timestamp

Getting file modification time on UNIX using utime in C

爷,独闯天下 提交于 2019-12-19 05:18:55
问题 I have been told by a professor that you can get a file's last modification time by using utime.h . However, the man page seem to cite that utime() only sets this value. How can I look up the last time a file was changed in C on a UNIX system? 回答1: This returns the file's mtime , the "time of last data modification". Note that Unix also has a concept ctime , the "time of last status change" (see also ctime, atime, mtime). #include <sys/types.h> #include <sys/stat.h> time_t get_mtime(const

How do I find the unix timestamp for the start of the next day in php?

牧云@^-^@ 提交于 2019-12-19 05:15:01
问题 I have a unix timestamp for the current time. I want to get the unix timestamp for the start of the next day. $current_timestamp = time(); $allowable_start_date = strtotime('+1 day', $current_timestamp); As I am doing it now, I am simply adding 1 whole entire day to the unix timestamp, when instead I would like to figure out how many seconds are left in this current day, and only add that many seconds in order to get the unix timestamp for the very first minute of the next day. What is the

mongodb: extract timestamp from ObjectID in json query

有些话、适合烂在心里 提交于 2019-12-19 03:42:13
问题 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? 回答1: You can do this fairly simply, at doc page Mongo Extended JSON (which is quite well hidden) you can find a table describing how

How to specify time zone (UTC) when converting to Unix time? (Python)

霸气de小男生 提交于 2019-12-18 16:56:40
问题 I have a utc timestamp in the IS8601 format and am trying to convert it to unix time. This is my console session: In [9]: mydate Out[9]: '2009-07-17T01:21:00.000Z' In [10]: parseddate = iso8601.parse_date(mydate) In [14]: ti = time.mktime(parseddate.timetuple()) In [25]: datetime.datetime.utcfromtimestamp(ti) Out[25]: datetime.datetime(2009, 7, 17, 7, 21) In [26]: datetime.datetime.fromtimestamp(ti) Out[26]: datetime.datetime(2009, 7, 17, 2, 21) In [27]: ti Out[27]: 1247815260.0 In [28]:

PHP strtotime() function wrong by 1 hour?

我的未来我决定 提交于 2019-12-18 14:48:14
问题 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

MySQL group by date and convert from unix timestamp

…衆ロ難τιáo~ 提交于 2019-12-18 13:37:48
问题 I have the following sql table (simplified) ID (int) title (text) date (int) -------------------------------------------- 1 Hello World 1378148920 2 Hello World2 1378182183 3 Hello World3 1378129838 4 Hello World4 1378146160 5 Hello World5 1378138038 .... The table has thousands of entries. I wan't to ask you if it is possible to build a SQL query that groups all the posts by date but only as day. So at the end I wan't to build a graph like this (for the last 5 days): 02.09.2013: 13 posts 01

Formatting date to human readable format

会有一股神秘感。 提交于 2019-12-18 12:11:20
问题 Lets say in my mysql database I have a timestamp 2013-09-30 01:16:06 and lets say this variable is $ts . How can I output this to show more like September 30th, 2013 ? 回答1: $timestamp = "2013-09-30 01:16:06"; echo date("F jS, Y", strtotime($timestamp)); //September 30th, 2013 Note the use of S to get the english ordinal suffix for the day. Since you're already using strtotime if you need a human readable data for the current time you can just use the keyword " now " as in strtotime("now")

Minimal implementation of gmtime algorithm?

人盡茶涼 提交于 2019-12-18 08:26:36
问题 Does anyone know of a simple gmtime or ctime implementation without consideration for timezone, no external dependencies, and a non-copyleft license (BSD/MIT/anything proprietary-safe)? Preferably in C, but basically anything that gives me the algorithm in its minimal form would work. I just need seconds since "Jan 1, 1970 00:00:00" broken down into year, day, month, hr, min, sec. And it's almost time to go home on a Friday so I'm feeling a bit lazy. 回答1: Try newlib http://sourceware.org

How to convert “YYYY-MM-DD hh:mm:ss” to UNIX timestamp in Java?

六月ゝ 毕业季﹏ 提交于 2019-12-18 07:24:41
问题 Or, maybe you know a better approach how to solve this problem. I get dates in the format of "YYYY—MM-DD HH:MM:SS" and need to calculate time difference between now then in approximate increments: 1 minute ago, 1 hour ago, etc. Any pointers much appreciated :) 回答1: Have a look at the SimpleDateFormat. You can define your pattern and parse it into a Java Date Object: SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = format.parse("your string goes here"); long

UNIX date: How to convert week number to a date range (Mon-Sun)?

和自甴很熟 提交于 2019-12-18 05:57:45
问题 I have list of week numbers extracted from huge log file, they were extracted using syntax: $ date --date="Wed Mar 20 10:19:56 2012" +%W; 12 I want to create a simple bash function which can convert these week numbers to a date range. I suppose function should accept 2 arguments: $number and $year, example: $ week() { ......... } $ number=12; year=2012 $ week $number $year "Mon Mar 19 2012" - "Sun Mar 25 2012" 回答1: With GNU date : $ cat weekof.sh function weekof() { local week=$1 year=$2