localtime

how to parse OffsetTime for format HHmmssZ

ぐ巨炮叔叔 提交于 2021-02-11 17:09:24
问题 I am trying to parse date string with format "HHmmssZ", OffsetTime.parse("115601Z", DateTimeFormatter.ofPattern("HHmmssZ")).toLocalTime() when i test it i get the exception : java.time.format.DateTimeParseException: Text '112322Z' could not be parsed at index 6 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.OffsetTime.parse(OffsetTime.java:327) 回答1: All the following will

how to parse OffsetTime for format HHmmssZ

左心房为你撑大大i 提交于 2021-02-11 17:05:16
问题 I am trying to parse date string with format "HHmmssZ", OffsetTime.parse("115601Z", DateTimeFormatter.ofPattern("HHmmssZ")).toLocalTime() when i test it i get the exception : java.time.format.DateTimeParseException: Text '112322Z' could not be parsed at index 6 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.OffsetTime.parse(OffsetTime.java:327) 回答1: All the following will

Convert UTC java.sql.Time to java.time.localtime with correct DST

那年仲夏 提交于 2021-02-10 06:14:39
问题 I have a problem to convert a java.sql.Time (UTC) which is fetched from a database to a java.time.LocalTime (GMT+1 DST). It is always missing the DST hour. So like a Time of 03:00 is only converted to a LocalTime of 04:00 instead of 05:00. //Saved UTC time in DB: 03:00 LocalTime.ofInstant(Instant.ofEpochMilli(sqlTime.getTime()), ZoneId.of("Europe/Berlin")); => 04:00 //expected 05:00 I guess the problem is that java.sql.Time saves the time with a default date of 1970-01-01 and in 1970 there

Saving a LocalTime in MySql TIME column

早过忘川 提交于 2021-01-03 05:27:45
问题 Backstory I recently came across a problem with saving a LocalTime to a TIME column in a MySQL database. Saving a value of 9:00 was causing 8:00 to be saved in the database. This problem did not occur on my dev environment (Windows), but did occur on two Linux machines we tried. My code was the following: preparedStatement.setObject(parameterIndex, localTime, JDBCType.TIME); After investigating, I eventually found that the MySQL JDBC driver was using java.sql.Time.valueOf(localTime) , then

same date when printing from st_mtime, st_ctime,st_atime

非 Y 不嫁゛ 提交于 2020-12-12 09:53:09
问题 So, I'm supposed to print the date of access of directories, modification and creation, but they all seem to be the same date. Here's my code: struct* tm date; struct stat fileStat; if(options[0] == 1 && options[1] == 0 && options[2] == 0 && options[3] == 0){ date = localtime(&(fileStat.st_mtime)); printf("M%02i/%d/%i-%02d:%02d", date->tm_mon,date->tm_mday, (date->tm_year + 1900)%100, date->tm_hour,date->tm_min); date = NULL; } else if(options[0] == 1 && options[1] == 1 && options[2] == 0 &&

Get the local date instead of UTC

橙三吉。 提交于 2020-06-29 04:19:05
问题 The following script calculates me next Friday and next Sunday date. The problem : the use of .toISOString uses UTC time. I need to change with something that outputs local time. I'm very new to javascript so I can't find the right property to use instead of .toIsostring. What should I do ? function nextWeekdayDate(date, day_in_week) { var ret = new Date(date || new Date()); ret.setDate(ret.getDate() + (day_in_week - 1 - ret.getDay() + 7) % 7 + 1); return ret; } let nextFriday =

Get the local date instead of UTC

纵饮孤独 提交于 2020-06-09 05:26:07
问题 The following script calculates me next Friday and next Sunday date. The problem : the use of .toISOString uses UTC time. I need to change with something that outputs local time. I'm very new to javascript so I can't find the right property to use instead of .toIsostring. What should I do ? function nextWeekdayDate(date, day_in_week) { var ret = new Date(date || new Date()); ret.setDate(ret.getDate() + (day_in_week - 1 - ret.getDay() + 7) % 7 + 1); return ret; } let nextFriday =

LocalTime() difference between two times

五迷三道 提交于 2020-05-23 12:40:13
问题 I have a flight itinerary program where I need to get difference between departure and arrival time. I get these specified times as String from the data. Here is my problem: import static java.time.temporal.ChronoUnit.MINUTES; import java.time.LocalTime; import java.time.format.DateTimeFormatter; public class test2 { public static void main(String[] args) { DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("HHmm"); LocalTime departure = LocalTime.parse("1139", dateFormat); LocalTime

How to parse time in any format with LocalTime.parse?

时光毁灭记忆、已成空白 提交于 2020-05-15 10:09:13
问题 I am having trouble using java's LocalTime to parse a string with hours, minutes, and seconds. LocalTime t = LocalTime.parse("8:30:17"); // Simplification This throws the following exception: Exception in thread "main" java.time.format.DateTimeParseException: Text '8:30:17' could not be parsed at index 0 回答1: You'll need to pass in a custom DateTimeFormatter like this: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm:ss"); LocalTime t = LocalTime.parse(times.get(i), formatter);