unix-timestamp

Convert String To date in PHP

大城市里の小女人 提交于 2019-12-18 02:47:17
问题 How can I convert this string 05/Feb/2010:14:00:01 to unixtime ? 回答1: For PHP 5.3 this should work. You may need to fiddle with passing $dateInfo['is_dst'], wasn't working for me anyhow. $date = '05/Feb/2010:14:00:01'; $dateInfo = date_parse_from_format('d/M/Y:H:i:s', $date); $unixTimestamp = mktime( $dateInfo['hour'], $dateInfo['minute'], $dateInfo['second'], $dateInfo['month'], $dateInfo['day'], $dateInfo['year'], $dateInfo['is_dst'] ); Versions prior, this should work. $date = '05/Feb/2010

Converting TIMESTAMP to unix time in PHP?

不想你离开。 提交于 2019-12-18 01:52:50
问题 Currently I store the time in my database like so: 2010-05-17 19:13:37 However, I need to compare two times, and I feel it would be easier to do if it were a unix timestamp such as 1274119041 . (These two times are different) So how could I convert the timestamp to unix timestamp? Is there a simple php function for it? 回答1: You're looking for strtotime() 回答2: You want strtotime: print strtotime('2010-05-17 19:13:37'); // => 1274123617 回答3: Getting a unixtimestamp: $unixTimestamp = time();

What is the easiest way to get current GMT time in Unix timestamp format?

房东的猫 提交于 2019-12-17 21:57:15
问题 Python provides different packages ( datetime , time , calendar ) as can be seen here in order to deal with time. I made a big mistake by using the following to get current GMT time time.mktime(datetime.datetime.utcnow().timetuple()) What is a simple way to get current GMT time in Unix timestamp? 回答1: I would use time.time() to get a timestamp in seconds since the epoch. import time time.time() Output: 1369550494.884832 For the standard CPython implementation on most platforms this will

Why does strtotime give different result in different timezone?

六月ゝ 毕业季﹏ 提交于 2019-12-17 20:51:37
问题 I am not sure why strtotime() in PHP returns different result in different timezone even though same date is given as parameter, does anyone know the answer? I also want to know, can I do similar task (converting a datetime to an int to do calculations easily) with another function which gives same result across different timezone? EDIT: An example: If I use strtotime('2011-09-19 00:00:00') shouldn't it just return the difference between 'January 1 1970 00:00:00' and '2011-09-19 00:00:00' in

uses for mongodb ObjectId creation time

别等时光非礼了梦想. 提交于 2019-12-17 15:18:06
问题 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? 回答1: I suppose since MongoDB ObjectId contain a timestamp, you can sort by 'created date' if you will sort by objectId: items.find.sort( [[

How do I deserialize timestamps that are in seconds with Jackson?

笑着哭i 提交于 2019-12-17 10:59:07
问题 I've got some JSON that has timestamps in seconds (i.e. a Unix timestamp): {"foo":"bar","timestamp":1386280997} Asking Jackson to deserialize this into an object with a DateTime field for the timestamp results in 1970-01-17T01:11:25.983Z , a time shortly after the epoch because Jackson is assuming it to be in milliseconds . Aside from ripping apart the JSON and adding some zeros, how might I get Jackson to understand the seconds timestamp? 回答1: I wrote a custom deserializer to handle

How to parse unix timestamp to time.Time

谁都会走 提交于 2019-12-17 10:15:36
问题 I'm trying to parse an Unix timestamp but I get out of range error. That doesn't really makes sense to me, because the layout is correct (as in the Go docs): package main import "fmt" import "time" func main() { tm, err := time.Parse("1136239445", "1405544146") if err != nil{ panic(err) } fmt.Println(tm) } Playground 回答1: The time.Parse function does not do Unix timestamps. Instead you can use strconv.ParseInt to parse the string to int64 and create the timestamp with time.Unix : package main

How to parse unix timestamp to time.Time

前提是你 提交于 2019-12-17 10:14:05
问题 I'm trying to parse an Unix timestamp but I get out of range error. That doesn't really makes sense to me, because the layout is correct (as in the Go docs): package main import "fmt" import "time" func main() { tm, err := time.Parse("1136239445", "1405544146") if err != nil{ panic(err) } fmt.Println(tm) } Playground 回答1: The time.Parse function does not do Unix timestamps. Instead you can use strconv.ParseInt to parse the string to int64 and create the timestamp with time.Unix : package main

how to convert a string to a Unix timestamp in javascript?

ⅰ亾dé卋堺 提交于 2019-12-17 09:43:59
问题 I want to convert a string "2013-09-05 15:34:00" into a Unix timestamp in javascript. Can any one tell how to do that? thanks. 回答1: You can initialise a Date object and call getTime() to get it in unix form. It comes out in milliseconds so you'll need to divide by 1000 to get it in seconds. (new Date("2013/09/05 15:34:00").getTime()/1000) It may have decimal bits so wrapping it in Math.round would clean that. Math.round(new Date("2013/09/05 15:34:00").getTime()/1000) 回答2: try (new Date("2013

Countdown timer using Moment js

我的梦境 提交于 2019-12-17 07:20:52
问题 I am making a countdown timer for an event page, i used moment js for this. Here is fiddle for this. I am calculating date difference between event date and current date (timestamp), then using "duration" method from moment js. But the time left is not coming as expected. Expected - 00:30m:00s Actual - 5h:59m:00s Code : <script> $(document).ready(function(){ var eventTime = '1366549200'; var currentTime = '1366547400'; var time = eventTime - currentTime; var duration = moment.duration(time