Questions tagged [datetime-parsing]

423 questions
6
votes
2 answers

Java Instant.parse on Date java 8

I have some legacy KML documents which includes a time stamp entry. Why is the below date not valid when using Instant to parse? Both methods are suppose to parse ISO 8601 formatted dates. String dateString = "2017-12-04T08:06:60Z" Using…
Jeryl Cook
  • 989
  • 17
  • 40
6
votes
1 answer

Convert String in 12 (PM /AM)Hour AM PM Time to 24 Hour time android

I have a problem in convert time coming from server and I want to convert it to 24 hour. I'm using the following code: String timeComeFromServer = "3:30 PM"; SimpleDateFormat date12Format = new SimpleDateFormat("hh:mm a"); SimpleDateFormat…
ahmad
  • 85
  • 1
  • 4
6
votes
2 answers

DateTime.ParseExact not working at all, why?

I am attempting to parse the following String into a DateTime object in c#: DateTime.ParseExact("20101108 230125", "yyyyMMdd hhmmss", null) although the value looks correct the ParseExact method just keeps giving me the following: String was not…
William Calleja
  • 4,055
  • 11
  • 41
  • 51
6
votes
7 answers

Java Date Format that allows - / or . as separators within date

What's the nicest way to parse a date that can be in one of the following formats "dd-MM-yyyy HH:mm" "dd/MM/yyyy HH:mm" "dd.MM.yyyy HH:mm" without creating 3 SimpleDateFormats and parsing against each one. Thanks
Tarski
  • 5,360
  • 4
  • 38
  • 47
5
votes
3 answers

java.text.ParseException: Unparseable date : "..."

I get this error with this code: SimpleDateFormat sdf = new SimpleDateFormat("EEEE dd MMMM HH:mm yyyy",myDateFormatSymbols); sdf.parse("понеділок 12 квітень 07:00 2021"); Whis is "Monday 12 April 07:00 2021". The thing is, whenever I change the day…
5
votes
5 answers

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

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"…
Yury
  • 69
  • 1
  • 7
5
votes
1 answer

SimpleDateFormat.parse() ignoring timezone?

I am trying to parse date string with timezone using this code for tests: SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZZZZZ", Locale.US); Calendar calendar =…
BArtWell
  • 4,176
  • 10
  • 63
  • 106
5
votes
2 answers

Can't convert string to ZonedDateTime: DateTimeParseException

I try to convert string from JSON to ZonedDateTime just like static String getWatchTime(JSONObject aJson, JSONObject bJson) { long difference = 0 ; try { String aTime = aJson.getString("time_utc_8"); String bTime =…
Zi-yan Tseng
  • 184
  • 1
  • 1
  • 14
5
votes
1 answer

Jackson / JavaTimeModule - handle different timezone offset formats

I'm calling an API (using Jersey) which returns Date Time with zone offset. Sometimes the data is in this format: "2017-03-28T14:40:00+01:00" and sometimes it is in this format (I've no control over this) "2017-03-28T14:40:00+0100" (where the ':'…
Kevin
  • 11,521
  • 22
  • 81
  • 103
5
votes
3 answers

How to parse string with long milliseconds (nanoseconds) part to DateTime?

I'm trying to figure-out the right string format of the following given date-time literal: 18-JUN-13 12.17.36.000000000 Using MSDN, I managed to composed the following format: "d'-'MMM'-'y'T'h'.'m'.'s'.'fff" But when using the DateTime.ParseExact,…
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
5
votes
5 answers

How can I parse this datetime string?

I can't figure it out, where did I go wrong? I got the following datetime string, and need to parse it to datetime: string timestr = "1/20/2014 12:05:16 AM" And I trying to parse it like this: DateTime.ParseExact( timestr, …
Jason94
  • 13,320
  • 37
  • 106
  • 184
5
votes
3 answers

Parsing this kind of string into DateTime - "Friday 22nd March 2013" (C#)

I've got a large chunk of text like this: ....advises that Friday 22nd March 2013 has the potential to be declared a day..... I have to locate and then parse DateTime in it (Friday 22nd March 2013). I can locate it and use DateTime.TryParse to get…
Sundance
  • 127
  • 1
  • 8
5
votes
1 answer

Convert general SQL time format in c# ( all variations )?

If I have theses general sql valid dates in c# strings : (each date can be in different order inside ) e.g. : 01 feb 2010 feb 01 2010 2010 01 feb ... ... I want to convert a string date to DateTime(c#). ( i want the ability to convert every…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
4
votes
2 answers

DateTime.TryParseExact() fails because of thread's culture info

I have the following line of code in existing implementation DateTime.TryParseExact( "15/11/2021 00:00:00", "dd/MM/yyyy HH:mm:ss", null, DateTimeStyles.None, out maturityDate); which returns false that means that the passed…
xenn_33
  • 855
  • 1
  • 10
  • 25
4
votes
2 answers

.Net 5 DateTime.ParseExact problems

Just migrated on .Net 5. The next code returns "01/01/0001 00:00:00 +00:00" in "date" variable. DateTime.TryParseExact( "Июн 16 2021", "MMМ d yyyy", CultureInfo.CreateSpecificCulture("ru-RU"), DateTimeStyles.None, out DateTime…
DmitryD
  • 51
  • 3