Questions tagged [datetime-parsing]
360 questions
16
votes
3 answers
How to check if string matches date pattern using time API?
My program is parsing an input string to a LocalDate object. For most of the time the string looks like 30.03.2014, but occasionally it looks like 3/30/2014. Depending on which, I need to use a different pattern to call…
user1019830
14
votes
2 answers
DateTimeFormatter weekday seems off by one
I'm porting an existing application from Joda-Time to Java 8 java.time.
I ran into a problem where parsing a date/time string that contains a 'day of week' value triggered an exception in my unit tests.
When parsing:
2016-12-21 20:50:25 Wednesday…
![](../../users/profiles/114196.webp)
Niels Basjes
- 9,714
- 8
- 45
- 60
13
votes
6 answers
How to parse date-time with two or three milliseconds digits in java?
Here is my method to parse String into LocalDateTime.
public static String formatDate(final String date) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SS");
LocalDateTime formatDateTime =…
![](../../users/profiles/1988876.webp)
brain storm
- 25,842
- 54
- 187
- 349
13
votes
1 answer
Why does this date parsing fail?
I'm trying to convert a string into a LocalDateTime object.
@Test
public void testDateFormat() {
String date = "20171205014657111";
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
LocalDateTime dt =…
![](../../users/profiles/4184113.webp)
user4184113
- 746
- 1
- 8
- 25
12
votes
1 answer
Why doesn't DateTime.ParseExact parse UTC format with the trailing Z?
Another ParseExact problem. I'm trying to parse a UTC formatted string to a datetime with the format of:
"YYYY-MM-DDThh:mm:ss.ssZ"
which is in UTC format, with the trailing Z. I can't parse exact it for some reason. I have tried the "u", "s", "o"…
![](../../users/profiles/89521.webp)
scope_creep
- 4,103
- 11
- 33
- 61
11
votes
1 answer
Jackson: parse custom offset date time
I have a model which has a timestamp property:
class Model {
@JsonProperty("timestamp")
private OffsetDateTime timestamp;
}
The format of the timestamp is as following:
2017-09-17 13:45:42.710576+02
OffsetDateTime is unable to parse…
![](../../users/profiles/8622137.webp)
Kwers T
- 113
- 1
- 1
- 4
10
votes
6 answers
Create DateTime from string without applying timezone or daylight savings
How do I create a DateTime var from a string which is already adjusted for UTC? I am running this on a machine set to BST (GMT+1). If I run the following line of code:
DateTime clientsideProfileSyncStamp = Convert.ToDateTime("20-May-2011…
![](../../users/profiles/603355.webp)
Journeyman
- 9,339
- 14
- 73
- 121
10
votes
2 answers
TryParseExact returns false, though I don't know why
Method TryParseExact in code block below returns true.
I would like to know why.
I think this date "2013.03.12" is invalid because this is not separated by slash but dot.
After I changed the CultureInfo "de-De" to "en-US", the method returns false.…
![](../../users/profiles/827804.webp)
Nigiri
- 2,759
- 4
- 22
- 47
9
votes
6 answers
Java 8 Time API - ZonedDateTime - specify default ZoneId when parsing
I am trying to write a generic method to return a ZonedDateTime given a date as String and its format.
How do we make ZonedDateTime to use the default ZoneId if it is not specified in the date String?
It can be done with java.util.Calendar, but I…
![](../../users/profiles/15789.webp)
RuntimeException
- 1,515
- 2
- 22
- 29
9
votes
2 answers
How to create DateTimeformatter with optional seconds arguments
I am trying to create a DateTimeformatter to validate following date times:
String date1 = "2017-07-06T17:25:28";
String date2 = "2017-07-06T17:25:28.1";
String date3 = "2017-07-06T17:25:28.12";
String date4 = "2017-07-06T17:25:28.123";
String date5…
![](../../users/profiles/4085383.webp)
Amit Garg
- 518
- 1
- 6
- 17
8
votes
1 answer
Java 8 DateTimeFormatter to ignore millisecond and zone
I am struggling with Java 8 DateTimeFormatter.
I would like to convert a given String to dateFormat and parse to LocalDateTime
Here is my code
DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
String text =…
![](../../users/profiles/5615185.webp)
J. Doem
- 415
- 3
- 16
8
votes
3 answers
Why does Java 8 DateTimeFormatter allows an incorrect month value in ResolverStyle.STRICT mode?
Why does this test pass, while the month value is obviously invalid (13)?
@Test
public void test() {
String format = "uuuuMM";
String value = "201713";
DateTimeFormatter.ofPattern(format).withResolverStyle(ResolverStyle.STRICT)
…
![](../../users/profiles/946800.webp)
Virginie
- 809
- 2
- 11
- 30
8
votes
4 answers
DateTimeFormatter Accepting Multiple Dates and Converting to One (java.time library)
I am trying to write a DateTimeFormatter that will allow me to take in multiple different String formats, and then convert the String formats to a specific type. Due to the scope of the project and the code that already exists, I cannot use a…
![](../../users/profiles/2926611.webp)
Alex Kornhauser
- 444
- 4
- 13
- 34
8
votes
4 answers
how to get a formatted date as milliseconds?
I have a formatted date from sqllite database, to use this in a graph view I need to format it in a long number.
The format is:
2012-07-11 10:55:21
how can I convert it to milliseconds?
![](../../users/profiles/1340537.webp)
Reyjohn
- 2,083
- 7
- 30
- 57
7
votes
3 answers
What system default date format to use?
I'm setting the standards for our application.
I've been wondering, what default date format should I choose to use ?
It should be:
Internationalization & timezone aware, the format should be able to represent user local time
Can be efficiently…
![](../../users/profiles/48062.webp)
Maxim Veksler
- 25,736
- 34
- 119
- 148