utc

C++ Converting a time string to seconds from the epoch

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a string with the following format: 2010-11-04T23:23:01Z The Z indicates that the time is UTC. I would rather store this as a epoch time to make comparison easy. What is the recomended method for doing this? Currently (after a quck search) the simplist algorithm is: 1: 2: Use mktime() to convert struct_tm to epoch time. // Problem here is that mktime uses local time not UTC time. 回答1: This is ISO8601 format. You can use strptime function to parse it with %FT%T%z argument. It is not a part of the C++ Standard though you can use open

How to convert UTC and local timezone in Java

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am curious about timezone in Java. I want to get UTC time in milliseconds from a device and send to server. Server will convert it to local timezone when it displays time to users. Timezone in my system is Australia/Sydney( UTC + 11:00), and I have got the result below when I tested timezone: int year = 2014; int month = 0; int date = 14; int hourOfDay = 11; int minute = 12; int second = 0; Calendar c1 = Calendar.getInstance(); c1.set(year, month, date, hourOfDay, minute, second); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH

pytz utc conversion

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What is the right way to convert a naive time and a tzinfo into an UTC time? Say I have: d = datetime(2009, 8, 31, 22, 30, 30) tz = timezone('US/Pacific') First way, pytz inspired: d_tz = tz.normalize(tz.localize(d)) utc = pytz.timezone('UTC') d_utc = d_tz.astimezone(utc) Second way, from UTCDateTimeField def utc_from_localtime(dt, tz): dt = dt.replace(tzinfo=tz) _dt = tz.normalize(dt) if dt.tzinfo != _dt.tzinfo: # Houston, we have a problem... # find out which one has a dst offset if _dt.tzinfo.dst(_dt): _dt -= _dt.tzinfo.dst(_dt) else: _dt

How to parse unix timestamp in golang

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 golang docs): package main import "fmt" import "time" func main() { tm, err := time.Parse("1136239445", "1405544146") if err !=nil{ panic(err) } fmt.Println(tm) } play 回答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 import ( "fmt" "time" "strconv" ) func main() { i,

Node.js - How to format a date string in UTC

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Using Node.js, I want to format a Date into the following string format: var ts_hms = new Date ( UTC ); ts_hms . format ( "%Y-%m-%d %H:%M:%S" ); How do I do that? 回答1: If you're using Node.js, you're sure to have EcmaScript 5, and so Date has a toISOString method. You're asking for a slight modification of ISO8601: new Date (). toISOString () > '2012-11-04T14:51:06.157Z' So just cut a few things out, and you're set: new Date (). toISOString (). replace ( /T/ , ' ' ). // replace T with a space replace ( /\..+/ , '' ) // delete the

Add hours to UTC dateTime

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am sure the answer is right in front of me, but I have a UTC dateTime that looks like this: 2014-01-02 04:02:58 All I want to do is add some hours to that. How can I achieve this in PHP? Further, how would I add days to it if I wanted to? 回答1: Use DateTime() . Unlike date() / strtotime() it is timezone and daylight savings time friendly. // PHP 5.2+ $dt = new DateTime('2014-01-02 04:02:58'); $dt->modify('+2 hours'); echo $dt->format('Y-m-d H:i:s'); $dt->modify('+2 days'); echo $dt->format('Y-m-d H:i:s'); See it in action Or // PHP 5.3+ $dt

Datetime module and Pandas to_datetime give different results

匿名 (未验证) 提交于 2019-12-03 01:40:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a string containing a UTC datetime utc_str = '2017-11-21T23:00+0100' which in my local time (Europe/Berlin) is: local_time = '2017-11-22 00:00' And is the desired value I would like to obtain from utc_string . I can convert utc_string to local_time just fine using: import datetime as dt utc_time = dt.datetime.strptime(date_str, '%Y-%m-%dT%H:%M%z') local_time = utc_time.replace(tzinfo=pytz.utc).astimezone(pytz.timezone('Europe/Berlin')) print(local_time.strftime('%Y-%m-%d %H:%M')) >>> 2017-11-22 00:00 However, when I use Pandas , I get

JavaScript: Convert UTC time to local time using timezone [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Javascript to convert UTC to local time 7 answers I have a UTC date time string and time zone name. I am getting this from a third party API. I need to convert the UTC time to local time of that timezone using JavaScript/NodeJS as well as get that time zone's current time. Is there any library/method available for the same? var timezone = "America/New_York";//This will always be in Olson format. var UTCTime = "2017-09-03T02:00:00Z"; var localTime; //I need to find the equivalent of UTCTime for

Convert to UTC Timestamp

匿名 (未验证) 提交于 2019-12-03 01:33:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: //parses some string into that format. datetime1 = datetime.strptime(somestring, "%Y-%m-%dT%H:%M:%S") //gets the seconds from the above date. timestamp1 = time.mktime(datetime1.timetuple()) //adds milliseconds to the above seconds. timeInMillis = int(timestamp1) * 1000 How do I (at any point in that code) turn the date into UTC format? I've been ploughing through the API for what seems like a century and cannot find anything that I can get working. Can anyone help? It's currently turning it into Eastern time i believe (however I'm in GMT but

Access TimeZoneInfo from SQL 2005 Server

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The .NET TimeZoneInfo class is great and I thought it would answer all my issues with recording data from multiple time zones in my SQL 2005 database. To convert a UTC datetime in the database to any other time zone i'd just get the time zone into a TimeZoneInfo class using TimeZoneInfo.FindSystemTimeZoneById() and then call the TimeZoneInfo.ConvertTimeFromUtc(). Brilliant! I'd just call this from the SQL .NET CLR! BUT...TimeZoneInfo has a Host Protection Attribute of MayLeakOnAbort. When I use VS 2008 to create an SQL function or stored