java.util.calendar

Shift date an hour when in dst

爱⌒轻易说出口 提交于 2019-12-11 05:38:22
问题 I am processing a file line by line. Each line has a date in the following format: YYMMDD HHMM The file is basically recording a reading every 15 minutes. The recording is using day light savings for the time zone it is in. The issue I am having is during spring ahead and fall back. The recording is duplicating dates when fall back occurs and a gap when fall back occurs. Fallback example: 141102 0100 141102 0115 141102 0130 141102 0145 141102 0200 141102 0115 - duplicate 141102 0130 -

SimpleDateFormat incorrectly parsing string

拟墨画扇 提交于 2019-12-11 03:32:32
问题 String s = 19.17.38.008000; DateFormat f = new SimpleDateFormat("HH.mm.ss.SSSSSS"); Date d = f.parse(s); system.out.println(d); this is the code I am running it runs fine except when it prints it prints the time 19:17:46. Please someone explain this to me As a side note: String s = 19.17.38.008000; DateFormat f = new SimpleDateFormat("HH.mm.ss"); Date d = f.parse(s); system.out.println(d); this code will print the same string correctly minus the milliseconds. Someone please tell me what I am

What does Calendar.UNDECIMBER do?

北城余情 提交于 2019-12-09 12:17:47
问题 There is a constant in the Calendar class called: UNDECIMBER . It describes the 13th month. Is there a useful purpose for this constant? In Wikipedia it is written that it is for the lunar calendar. But there is no implementation for such calendar. And does there exist any solutions for the 14th month (Duodecimber)? I didn't found so much in the web, and I would like to find out more about this topic. 回答1: As already said, some lunar (and other ancient) calendars have 13 months. One example

How to Pick Timezone from ISO 8601 format String into a Calendar instace

那年仲夏 提交于 2019-12-01 23:26:25
问题 As an input I have a string which is a String in ISO 8601 to represent date. For example: "2017-04-04T09:00:00-08:00" The last part of String , which is "-08:00" denotes TimeZone Offset. I convert this string into a Calendar instance as shown below: Calendar calendar = GregorianCalendar.getInstance(); Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(iso8601Date); calendar.setTime(date); iso8601Date is "2017-04-04T09:00:00-08:00" But this does not pick timezone and

What is the equivalent of Calendar.roll in java.time?

我的未来我决定 提交于 2019-12-01 22:29:32
I was studying the old Calendar API to see how bad it was, and I found out that Calendar has a roll method. Unlike the add method, roll does not change the values of bigger calendar fields. For example, the calendar instance c represents the date 2019-08-31. Calling c.roll(Calendar.MONTH, 13) adds 13 to the month field, but does not change the year, so the result is 2019-09-30. Note that the day of month changes, because it is a smaller field. Related I tried to find such a method in the modern java.time API. I thought such a method has to be in LocalDate or LocalDateTime , but I found nothing

How to Pick Timezone from ISO 8601 format String into a Calendar instace

与世无争的帅哥 提交于 2019-12-01 22:09:48
As an input I have a string which is a String in ISO 8601 to represent date. For example: "2017-04-04T09:00:00-08:00" The last part of String , which is "-08:00" denotes TimeZone Offset. I convert this string into a Calendar instance as shown below: Calendar calendar = GregorianCalendar.getInstance(); Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US).parse(iso8601Date); calendar.setTime(date); iso8601Date is "2017-04-04T09:00:00-08:00" But this does not pick timezone and if I get timezone from Calendar instance, it gives currently set instance of the laptop and does not

Setting values of Java Calendar does not give expected date-time

Deadly 提交于 2019-11-30 17:50:33
I have an hour, minute, date and millisecond timestamp, and am trying to create a Date object representing the time. The timestamp is provided in Eastern Daylight Time. In dissecting the problem, I created some simple test code to see what was happening and have observed the following: Date today = new Date(); int hour = 4, min = 0, sec = 0, ms = 64; boolean print = true; Calendar cal = GregorianCalendar.getInstance(); if(print) System.out.println("After initializing, time is: "+cal.getTime()); cal.clear(); if(print) System.out.println("After clearing, time is: "+cal.getTime()); cal.setTime

Set time to 00:00:00

六眼飞鱼酱① 提交于 2019-11-27 03:21:59
I have a problem resetting hours in Java. For a given date I want to set the hours to 00:00:00. This is my code : /** * Resets milliseconds, seconds, minutes and hours from the provided date * * @param date * @return */ public static Date trim(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR, 0); return calendar.getTime(); } The problem is that sometimes the time is 12:00:00 and sometimes it is 00:00:00 and when I query the