localdate

Problem with parse a LocalDateTime using java 8

[亡魂溺海] 提交于 2020-07-22 08:55:41
问题 I have this code, it's a simple string that I want to parse it to a LocalDateTime import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; public class DateClass { /** * @param args the command line arguments */ public static void main(String[] args) { String dateRaw = "2019-05-03 7:05:03"; DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendPattern("uuuu-mm-dd HH:mm:ss").toFormatter(); LocalDateTime date=

Problem with parse a LocalDateTime using java 8

岁酱吖の 提交于 2020-07-22 08:53:46
问题 I have this code, it's a simple string that I want to parse it to a LocalDateTime import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; public class DateClass { /** * @param args the command line arguments */ public static void main(String[] args) { String dateRaw = "2019-05-03 7:05:03"; DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendPattern("uuuu-mm-dd HH:mm:ss").toFormatter(); LocalDateTime date=

How can you make LocalDate to return Date in a specific format?

♀尐吖头ヾ 提交于 2020-06-29 06:21:49
问题 How can you make LocalDate to return Date in a specific format ? Ex . LocalDate ld = LocalDate.now(); The above statement will return date like 2018-11-24 but i want it to return like 24-11-2018 . ** Dont say use formatter because formatter will not return date , it will return String which is of no use for me . 回答1: Your question is contradictory, for example you want "24-11-2018" but also want "date" instead of "String" and overlook the fact that "24-11-2018" is a date in string form. A

How can you make LocalDate to return Date in a specific format?

我的未来我决定 提交于 2020-06-29 06:21:10
问题 How can you make LocalDate to return Date in a specific format ? Ex . LocalDate ld = LocalDate.now(); The above statement will return date like 2018-11-24 but i want it to return like 24-11-2018 . ** Dont say use formatter because formatter will not return date , it will return String which is of no use for me . 回答1: Your question is contradictory, for example you want "24-11-2018" but also want "date" instead of "String" and overlook the fact that "24-11-2018" is a date in string form. A

Unable to Convert String to localDate with custom pattern [duplicate]

喜你入骨 提交于 2020-06-29 04:42:55
问题 This question already has answers here : How to format LocalDate object to MM/dd/yyyy and have format persist (4 answers) Closed 14 days ago . import java.util.*; import java.lang.*; import java.io.*; import java.time.*; import java.time.format.*; import java.text.*; public class ConvertStringToDate { public static void main(String[] args)throws Exception { String date = "2020-06-14"; DateTimeFormatter Stringformatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // convert String to LocalDate

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 =

How to convert from Instant to LocalDate

最后都变了- 提交于 2020-06-24 08:09:28
问题 I have an Instant coming from a source that should, according to the spec, be a LocalDate, but don't see any methods in LocalDate for the conversion. What is the best way to do this? 回答1: LocalDate.ofInstant(...); I believe was added in Java 9. LocalDateTime has that method in Java 8. yourInstant.atZone(yourZoneId).toLocalDate(); Will work with earlier versions for LocalDate... 回答2: Other answers provided the mechanics for the transformation, but I wanted to add some background on the meaning

How can I return LocalDate.now() in milliseconds?

a 夏天 提交于 2020-06-22 09:35:21
问题 I create date now: ZoneId gmt = ZoneId.of("GMT"); LocalDateTime localDateTime = LocalDateTime.now(); LocalDate localDateNow = localDateTime.toLocalDate(); Then I want return this date in milliseconds: localDateNow.atStartOfDay(gmt) - 22.08.2017 localDateNow.atStartOfDay(gmt).toEpochSecond(); - 1503360000 (18.01.70) How can I return LocalDate.now() in milliseconds? 回答1: Calling toInstant().toEpochMilli() , as suggested by @JB Nizet's comment, is the right answer, but there's a little and

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 =