utc

JavaScript - Parse UTC Date

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I parse a simple date string and let JavaScript know that it's actually a UTC date? Currently, if I do new Date('2015-08-27') it converts it to my timezone. 回答1: You can do append 'T00:00:00.000Z' to make the time zone specific (Z indicates UTC) new Date('2015-08-27' + 'T00:00:00.000Z') Note that new Date('2015-08-27') is treated differently in ES5 (UTC) vs. ES6 (Local), so you can't expect it any correction to be work consistently if you were planning to to hard code it (i.e. don't do it) Also, do note that your console.log might

Storing datetime as UTC in PHP/MySQL

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Everywhere I read about converting time to a user's timezone says that the best method is to store a date and time in UTC then just add the user's timezone offset to this time. How can I store a date in UTC time? I use the MySQL DATETIME field. When adding a new record to MySQL in my PHP code I would use now() to insert into MySQL DATETIME. Would I need to use something different than now() to store UTC time? 回答1: MySQL: UTC_TIMESTAMP() Returns the current UTC date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS.uuuuuu format,

How to get an UTC date string in Python? [duplicate]

狂风中的少年 提交于 2019-12-03 02:20:13
This question already has answers here : How to get UTC time in Python? (7 answers) How to print a date in a regular format? (22 answers) I am trying to get utc date string as "YYYYMMDD" For now I do the following, nowTime = time.gmtime(); nowDate = date(nowTime.tm_year, nowTime.tm_mon, nowTime.tm_mday) print nowDate.strftime('%Y%m%d') I used to do: datetime.date.today().strftime() but this gives me date string in local TZ How can I get an UTC date string? from datetime import datetime, timezone datetime.now(timezone.utc).strftime("%Y%m%d") Or as Davidism pointed out, this would also work:

Moment.Js: Offsetting dates using UTC and Timezone offset

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to adjust a time using a timezone offset and a UTC timestamp. I am running the following code: var date = { utc : '2013-10-16T21:31:51' , offset : - 480 } var returnDate = moment ( date . utc ). utc (). zone ( date . offset ). format ( 'MM/DD/YYYY h:mm A' ); What I am expecting is: 10/16/2013 1:31 PM but I am ending up with 10/17/2013 9:31 AM 回答1: Here is what worked for me: var date = { utc : '2013-10-16T21:31:51' , offset : 480 } var returnDate = moment . utc ( date . utc ). zone ( date . offset ). format ( 'MM/DD

How do I print a Python datetime in the local timezone?

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I have a variable t that's set to this: datetime.datetime(2009, 7, 10, 18, 44, 59, 193982, tzinfo=<UTC>) If I say str(t) , i get: '2009-07-10 18:44:59.193982+00:00' How can I get a similar string, except printed in the local timezone rather than UTC? 回答1: Think your should look around: datetime.astimezone() http://docs.python.org/library/datetime.html#datetime.datetime.astimezone Also see pytz module - it's quite easy to use -- as example: eastern = timezone('US/Eastern') http://pytz.sourceforge.net/ Example: from datetime import

Convert string date to timestamp in Python

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to convert a string in the format "%d/%m/%Y" to timestamp? "01/12/2011" -> 1322697600 回答1: >>> import time >>> import datetime >>> s = "01/12/2011" >>> time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple()) 1322697600.0 回答2: To convert the string into a date object: from datetime import date, datetime date_string = "01/12/2011" date_object = date(*map(int, reversed(date_string.split("/")))) assert date_object == datetime.strptime(date_string, "%d/%m/%Y").date() The way to convert the date object into POSIX timestamp depends

How to get system timezone setting and pass it to pytz.timezone?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: We can use time.tzname get a local timezone name, but that name is not compatible with pytz.timezone . In fact, the name returned by time.tzname is ambiguous. This method returns ('CST', 'CST') in my system, but 'CST' can indicate four timezones: Central Time Zone (North America) - observed in North America's Central Time Zone China Standard Time Chungyuan Standard Time - the term "Chungyuan Standard Time" is now rarely in use in Taiwan Australian Central Standard Time (ACST) 回答1: tzlocal module returns pytz tzinfo's object

Can&#039;t subtract offset-naive and offset-aware datetimes

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a timezone aware timestamptz field in PostgreSQL. When I pull data from the table, I then want to subtract the time right now so I can get it's age. The problem I'm having is that both datetime.datetime.now() and datetime.datetime.utcnow() seem to return timezone unaware timestamps, which results in me getting this error: TypeError: can't subtract offset-naive and offset-aware datetimes Is there a way to avoid this (preferably without a third-party module being used). EDIT: Thanks for the suggestions, however trying to adjust the

Convert Date/Time for given Timezone - java

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to convert this GMT time stamp to GMT+13: 2011-10-06 03:35:05 I have tried about 100 different combinations of DateFormat, TimeZone, Date, GregorianCalendar etc. to try to do this VERY basic task. This code does what I want for the CURRENT TIME: Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT")); DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z"); formatter.setTimeZone(TimeZone.getTimeZone("GMT+13")); String newZealandTime = formatter.format(calendar.getTime()); But what I want is to set the time

Convert UTC date time to local date time

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: From the server I get a datetime variable in this format: 6/29/2011 4:52:48 PM and it is in UTC time. I want to convert it to the current user’s browser time using JavaScript. How this can be done using JavaScript or jQuery? 回答1: Append 'UTC' to the string before converting it to a date in javascript: var date = new Date('6/29/2011 4:52:48 PM UTC'); date.toString() // "Wed Jun 29 2011 09:52:48 GMT-0700 (PDT)" 回答2: This is an universal solution: function convertUTCDateToLocalDate(date) { var newDate = new Date(date.getTime()+date