Questions tagged [datetime-parsing]

360 questions
7
votes
6 answers

Failed to parse single digit hour and lowercase am-pm of day into Java 8 LocalTime

When I try to run the following code: LocalTime test = LocalTime.parse("8:00am", DateTimeFormatter.ofPattern("hh:mma")); I get this: Exception in thread "main" java.time.format.DateTimeParseException: Text '8:00am' could not be parsed at index…
benstpierre
  • 30,487
  • 46
  • 163
  • 272
7
votes
2 answers

Java 8 Parse ISO-8601 date ignoring presence (or absence) of timezone

My application should be able to parse date ignoring timezone (I always know for sure that it is UTC). The problem is that the date might come in both following forms - 2017-09-11T12:44:07.793Z 0001-01-01T00:00:00 I can parse the first one using…
silent-box
  • 1,392
  • 1
  • 15
  • 32
7
votes
1 answer

java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME fails to parse time zone names

I'm trying to parse timestamps from a data source that is defined as using RFC1123-compatible date time specifications. My code is: value = Instant.from (DateTimeFormatter.RFC_1123_DATE_TIME.parse (textValue)); This works fine for some data, but I…
Jules
  • 13,417
  • 7
  • 75
  • 117
7
votes
1 answer

Jackson - Can't deserialize datetime with timezone offset 'unparsed text found at index 23'

My datetime has to come from frontend with timezone offset: 2017-07-04T06:00:00.000+01:00 I cannot deserialize it with Jackson. The error is: Text '2017-07-04T06:00:00.000+01:00' could not be parsed, unparsed text found at index 23; I was trying…
Marek Urbanowicz
  • 9,057
  • 7
  • 48
  • 74
7
votes
4 answers

Parsing ISO-8601 DateTime with offset with colon in Java

I have a trouble with parsing date time in java, I have a strange date time format. How can I parse 2013-04-03T17:04:39.9430000+03:00 date time in java to format dd.MM.yyyy HH:mm in java?
vtokmak
  • 1,452
  • 6
  • 31
  • 66
7
votes
1 answer

parsing date string in python (convert string to date)

I have a datetime string in the form of a string as: 2011-10-23T08:00:00-07:00 How do i parse this string as the datetime object. I did the following reading the documentation: date = datetime.strptime(data[4],"%Y-%m-%d%Z") BUt I get the error …
frazman
  • 27,605
  • 60
  • 159
  • 243
7
votes
1 answer

Correctly parse date string with timezone information

I'm receiving a formatted date string like this via the pivotal tracker API: "2012/06/05 17:42:29 CEST" I want to convert this string to a UTC datetime object, it looks like python-dateutil does not recognize that timezone, pytz doesn't know it…
Strayer
  • 2,820
  • 2
  • 24
  • 34
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
  • 65
  • 3
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
  • 3,716
  • 11
  • 39
  • 46
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,132
  • 4
  • 35
  • 46
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
1 answer

How to parse the expiration date of a JWT to a time.Time() in Go?

I'd like to parse the expiration date (exp) from a JSON Web Token (JWT) without verifying it. I've tried the following script (in an attempt to follow How to parse unix timestamp to time.Time): package main import ( "fmt" "log" …
Kurt Peek
  • 34,968
  • 53
  • 191
  • 361
5
votes
6 answers

How to convert UTC Date String and remove the T and Z in Java?

Am using Java 1.7. Trying to convert: 2018-05-23T23:18:31.000Z into 2018-05-23 23:18:31 DateUtils class: public class DateUtils { public static String convertToNewFormat(String dateStr) throws ParseException { TimeZone utc =…
PacificNW_Lover
  • 4,008
  • 18
  • 76
  • 122
5
votes
3 answers

java.time DateTimeFormatter parsing with flexible fallback values

I am trying to port some code from joda time to java time. JodaTime had the possibility to specify a fallback value for the year like this parser.withDefaultYear((new DateTime(DateTimeZone.UTC)).getYear()).parseDateTime(text); Regardless how the…
alr
  • 1,654
  • 1
  • 10
  • 10
5
votes
3 answers

How to convert a given time (String) to a LocalTime?

I will be asking a user to enter a specific time: 10AM, 12:30PM, 2:47PM, 1:09AM, 5PM, etc. I will be using a Scanner to get the user's input. How can I parse/convert that String to a LocalTime object? Is there any built-in function in Java that…
SVCS1994
  • 133
  • 2
  • 12
1 2
3
23 24