utc

python: utcfromtimestamp vs fromtimestamp, when the timestamp is based on utcnow()

落花浮王杯 提交于 2020-06-16 03:16:14
问题 Pretty sure it's an easy one but I don't get it. My local TZ is currently GMT+3, and when I take timestamp from datetime.utcnow().timestamp() it is indeed giving me 3 hours less than datetime.now().timestamp() During another process in my flow, I take that utc timestamp and need to turn it into datetime. When I'm doing fromtimestamp I get the right utc hour, but when I'm using utcfromtimestamp I get another 3 hours offset. The documentation, though, asks me to use fromtimestamp for local

python: utcfromtimestamp vs fromtimestamp, when the timestamp is based on utcnow()

不羁的心 提交于 2020-06-16 03:16:12
问题 Pretty sure it's an easy one but I don't get it. My local TZ is currently GMT+3, and when I take timestamp from datetime.utcnow().timestamp() it is indeed giving me 3 hours less than datetime.now().timestamp() During another process in my flow, I take that utc timestamp and need to turn it into datetime. When I'm doing fromtimestamp I get the right utc hour, but when I'm using utcfromtimestamp I get another 3 hours offset. The documentation, though, asks me to use fromtimestamp for local

How to convert UTC Date String and remove the T and Z in Java?

余生颓废 提交于 2020-06-11 06:08:48
问题 Am using Java 1.7. Trying to convert: 2018-05-23T23:18:31.000Z into 2018-05-23 23:18:31 DateUtils class: public class DateUtils { public static String convertToNewFormat(String dateStr) throws ParseException { TimeZone utc = TimeZone.getTimeZone("UTC"); SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); sdf.setTimeZone(utc); Date convertedDate = sdf.parse(dateStr); return convertedDate.toString(); } } When trying to use it: String convertedDate = DateUtils.convertToNewFormat(

How to convert UTC Date String and remove the T and Z in Java?

匆匆过客 提交于 2020-06-11 06:08:09
问题 Am using Java 1.7. Trying to convert: 2018-05-23T23:18:31.000Z into 2018-05-23 23:18:31 DateUtils class: public class DateUtils { public static String convertToNewFormat(String dateStr) throws ParseException { TimeZone utc = TimeZone.getTimeZone("UTC"); SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); sdf.setTimeZone(utc); Date convertedDate = sdf.parse(dateStr); return convertedDate.toString(); } } When trying to use it: String convertedDate = DateUtils.convertToNewFormat(

PHP UTC to Local Time

送分小仙女□ 提交于 2020-05-25 03:28:28
问题 Server Environment Redhat Enterprise Linux PHP 5.3.5 Problem Let's say I have a UTC date and time such as 2011-04-27 02:45 and I want to convert it to my local time, which is America/New_York. Three questions: 1.) My code below might solve the problem, would you agree? <?php date_default_timezone_set('America/New_York'); // Set timezone. $utc_ts = strtotime("2011-04-27 02:45"); // UTC Unix timestamp. // Timezone offset in seconds. The offset for timezones west of UTC is always negative, //

Swift: Compare date by days

风流意气都作罢 提交于 2020-05-10 14:04:07
问题 I try to compare two days ignoring time. So I use calendar.compare(date1, to: date2, toGranularity: .day) BUT when transfering the string date to Date type, it is transformed to UTC. So it will be "moved" from 1.1.2016 0:05 to 31.12.2015 11:05 pm. When comparing daywise, this includes only the remaining hour. Before conversion it was 24 hours. Any idea to handle this issue without much effort? Additionally: The code: var dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy

Swift: Compare date by days

主宰稳场 提交于 2020-05-10 14:02:20
问题 I try to compare two days ignoring time. So I use calendar.compare(date1, to: date2, toGranularity: .day) BUT when transfering the string date to Date type, it is transformed to UTC. So it will be "moved" from 1.1.2016 0:05 to 31.12.2015 11:05 pm. When comparing daywise, this includes only the remaining hour. Before conversion it was 24 hours. Any idea to handle this issue without much effort? Additionally: The code: var dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy

Swift: Compare date by days

纵饮孤独 提交于 2020-05-10 14:01:14
问题 I try to compare two days ignoring time. So I use calendar.compare(date1, to: date2, toGranularity: .day) BUT when transfering the string date to Date type, it is transformed to UTC. So it will be "moved" from 1.1.2016 0:05 to 31.12.2015 11:05 pm. When comparing daywise, this includes only the remaining hour. Before conversion it was 24 hours. Any idea to handle this issue without much effort? Additionally: The code: var dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy

Swift: Compare date by days

假如想象 提交于 2020-05-10 13:55:24
问题 I try to compare two days ignoring time. So I use calendar.compare(date1, to: date2, toGranularity: .day) BUT when transfering the string date to Date type, it is transformed to UTC. So it will be "moved" from 1.1.2016 0:05 to 31.12.2015 11:05 pm. When comparing daywise, this includes only the remaining hour. Before conversion it was 24 hours. Any idea to handle this issue without much effort? Additionally: The code: var dateFormatter = DateFormatter() dateFormatter.dateFormat = "dd-MM-yyyy

Convert from UTC to local timezone give wrong result

烂漫一生 提交于 2020-05-09 11:55:22
问题 Background I need to convert time string with format: "HH:mm" from UTC to local timezone. For example if UTC time is 09:00, local time (Stockholm/Europe) should be two hours ahead. Problem When I convert 09:00 (UTC) to Stockholm/Europe time I get 10:00. It should be 11:00. func UTCToLocal(date:String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH:mm" dateFormatter.timeZone = TimeZone(abbreviation: "UTC") let dt = dateFormatter.date(from: date) dateFormatter