timezone

Calendar.getTime() fails with java.lang.IllegalArgumentException:MINUTE for Asia/Singapore timezone

余生颓废 提交于 2020-12-11 00:56:09
问题 Why is this code failing? The purpose was to remove the time part. String dateStr = "1982-01-01"; String timeZoneID = "Asia/Singapore"; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(dateStr); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone(timeZoneID)); calendar.setLenient(false); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0);

Calendar.getTime() fails with java.lang.IllegalArgumentException:MINUTE for Asia/Singapore timezone

a 夏天 提交于 2020-12-11 00:50:26
问题 Why is this code failing? The purpose was to remove the time part. String dateStr = "1982-01-01"; String timeZoneID = "Asia/Singapore"; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(dateStr); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone(timeZoneID)); calendar.setLenient(false); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0);

Get all available timezones

旧城冷巷雨未停 提交于 2020-12-01 11:53:32
问题 I'm currently working on an application that is required to support multiple timezones. For that, I'm using the dateutil library. Now, I need a way to present the user a list of all available timezones the dateutil library supports. Also, is it advisable to store the tz as strings in the database like "Europe/Berlin"? 回答1: dateutil will use the OS timezone info, but does carry it's own compressed timezone info file too. You could list the available names from the utility code that loads this

How to get UTC offset in seconds in android

白昼怎懂夜的黑 提交于 2020-12-01 00:40:33
问题 I'm trying to get the UTC offset in seconds in android. Since the emulator keeps returning 0, I can't tell if I'm doing this correctly or not. Calendar c=Calendar.getInstance(); TimeZone tz=c.getTimeZone(); int offsetFromUtc=tz.getOffset(0)/1000; When I put 0 in the tz.getOffset it means I just want the number of seconds from gmt. Let me know if what Im doing is correct. Thanks 回答1: Time Zone offsets can change during the year, perhaps the most common reason is Daylight Savings Time. Instead

How can i convert time zone string to the TimeZone Object in java?

本小妞迷上赌 提交于 2020-11-29 09:01:24
问题 I hava serval time zone strings in utc format, such as "UTC+08:00", "UTC-05:00", the question is how can i convert these utc format strings to the TimeZone Object(java.util.TimeZone) in java? i have tried to convert by zoneId as follows, but did not work: ZoneId zoneId = ZoneId.of("UTC+08:00"); TimeZone timeZone = TimeZone.getTimeZone(zoneId); i know TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai"); would work, but i do not know the mapping between "UTC+08:00" and "Asia/Shanghai" 回答1

How can i convert time zone string to the TimeZone Object in java?

喜欢而已 提交于 2020-11-29 08:56:32
问题 I hava serval time zone strings in utc format, such as "UTC+08:00", "UTC-05:00", the question is how can i convert these utc format strings to the TimeZone Object(java.util.TimeZone) in java? i have tried to convert by zoneId as follows, but did not work: ZoneId zoneId = ZoneId.of("UTC+08:00"); TimeZone timeZone = TimeZone.getTimeZone(zoneId); i know TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai"); would work, but i do not know the mapping between "UTC+08:00" and "Asia/Shanghai" 回答1

How to show the difference in time after the daylight saving started in Java?

别来无恙 提交于 2020-11-24 20:13:32
问题 I wanted to check the difference in time before and after the daylight saving time started. I am using a JVM where timezone has some issue with DST WRT Brazilian time. I could see the output where it says that 21st October falls under DST, which is wrong as the daylight saving started on 4th of November. I would like to see the timing difference which is 1 Hour in between 20th of October and 21st of October, which I could see in my application because of JRE Timezone issue. Is there any way I

How to show the difference in time after the daylight saving started in Java?

别等时光非礼了梦想. 提交于 2020-11-24 20:12:37
问题 I wanted to check the difference in time before and after the daylight saving time started. I am using a JVM where timezone has some issue with DST WRT Brazilian time. I could see the output where it says that 21st October falls under DST, which is wrong as the daylight saving started on 4th of November. I would like to see the timing difference which is 1 Hour in between 20th of October and 21st of October, which I could see in my application because of JRE Timezone issue. Is there any way I

PostgreSQL timestamp踩坑记录

筅森魡賤 提交于 2020-11-24 08:39:34
PostgreSQL timestamp踩坑记录 项目Timezone情况 NodeJS: UTC+08 PostgreSQL: UTC+00 timestampTest.js const { Client } = require('pg') const client = new Client() client.connect() let sql = `` client.query(sql, (err, res) => { console.log(err ? err.stack : res.rows[0].datetime) client.end() }) 不同时区 to_timestamp 查询结果 测试输入数据为 1514736000 (UTC时间 2017-12-31 16:00:00 ,北京时间 2018-01-01 00:00:00 ) 1、 timezone = UTC BEGIN; SET TIME ZONE 'UTC'; SELECT to_timestamp(1514736000) as datetime; END; 直接查询: 2017-12-31 16:00:00+00 YES pg查询: 2017-12-31T16:00:00.000Z YES 2、 timezone = PRC BEGIN; SET TIME ZONE 'PRC'; SELECT to