Unparseable date +01:00 groovy - date

How to parse this date format?
2019-05-14T15:07:19.000+01:00
I have used "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" but I am getting an unparseable date error.
have also tried these:
yyy-MM-dd'T'HH:mm:ss.SSSZZ
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
yyyy-MM-dd'T'HH:mm:ss.SSSXXX
but these also have unparseable date error.
Any help would be much appreciated.
Thanks :)
Below is the error seen.
Error executing data process; Caused by: Error executing data process; Caused by: Unparseable date: "2019-05-14T15:07:19.000+01:00" (in groovy2 script); Caused by: Unparseable date: "2019-05-14T15:07:19.000+01:00"

If you're running on top of Java 8, you can use ZonedDateTime to parse this by simply:
import java.time.ZonedDateTime
ZonedDateTime.parse("2019-05-14T15:07:19.000+01:00")

Related

Get a DateTime with an specific pattern with nscala-time

I am trying to get this pattern 'dd-MM-yyyy' with a variable of type DateTime
#{DateTimeFormat.forPattern("dd-MM-YYYY").parseDateTime(user.birthday.toString)}
But I am getting this error
java.lang.IllegalArgumentException: Invalid format: "2015-12-10T00:00:00.000Z" is malformed at "15-12-10T00:00:00.000Z"
Is there a way to do this with nscala-time?
makes a difference if I am using UTC?
UPDATE
For the moment I am casting to Date and doing this
#{Dates.format(user.birthday.toDate, "dd-MM-YYYY")}
But maybe is a better way without casting
thank you
So, if I understood your question correctly, you are trying to achieve the following:
Parse date from a string using a date format
Print/Display the date in another format.
Try the below:
#{Dates.format(DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parseDateTime(user.birthday.toString), "dd-MM-YYYY")}

Scala Joda Time Format Malformed

I can't find many Scala examples with Joda time especially with formatting but here is the error:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "2015-12-11T13:35:45.732-05:00" is malformed at "15-12-11T13:35:45.732-05:00"
Here is the code:
val now = DateTime.now.toString()
val dtf = DateTimeFormat.forPattern("MM-dd-yyyy HH:mm:ss");
val timeForm = dtf.parseDateTime(now)
Most of the java exmaples all seem to work fine with this?
It has nothing to do with Scala. MM-dd-yyyy HH:mm:ss means the string will start with month, then day, etc. (see http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html for the meaning of characters in the patterns). 2015-12-11T13:35:45.732-05:00 obviously doesn't. Either use val now = dtf.printDateTime(DateTime.now) to print current datetime in the same format you are planning to parse, or use the correct format to parse it.

MATLAB: Datenum format mismatch

I was working to convert a table of strings to a datenum object using MATLAB 2010a.
>> datenum('01-Jan-11', 'dd-mmm-yy')
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
>> datenum('02-Jan-11', 'dd-mmm-yy')
ans =
734505
>> datenum('03-Jan-11', 'dd-mmm-yy')
??? Error using ==> datenum at 182
DATENUM failed.
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
>> datenum('04-Jan-11', 'dd-mmm-yy')
ans =
734507
I am not able to understand the reason for this error. Can any one please elaborate?
I already see this problem at matlab2010, but didn`t find at Matlab2015. This sounds be a old bug
if you call again datenum('01-Jan-11', 'dd-mmm-yy') you will see that the second try this will work even if the first time didn`t work.
The only way to work around with this was puting a try catch statement and puting the datenum again at catch. This worked very well at my case.
Try to do this
try
datenum('01-Jan-11', 'dd-mmm-yy');
catch
datenum('01-Jan-11', 'dd-mmm-yy');
end
This will work for you

Talend parse date: unable to parse

I'm trying to insert data in my Database, my input is a string, representing a date in this format: yyyyMMdd ("20140525")
I try this in talend :
TalendDate.parseDate("yyyyMMdd",row1.date_pre_contrat)
but at runtime it does not work...
I've also tried
TalendDate.parseDate("yyyy-MM-dd",row1.date_pre_contrat)
but the result is the same.
Does someone have a any clue on what the problem is?
Solution found:
it was because i didn't tell Talend not to analyse the first line which contains the title.
Sorry for this

How to parse a date with timezone correctly?

I'm trying to convert a string of text into a date with the following code:
//Input String
str = "14/01/26,12:13:13+00"
//Format
format = new java.text.SimpleDateFormat("yy/MM/dd,HH:mm:ssz")
//Conversion
format.parse(str)
But I obtain the following:
Exception: Unparseable date: "14/01/26,12:13:13+00"
How does my format have to be changed in order to parse this date correctly?
+00 is invalid time zone. It should be +0000.
You could add 00 to str and replace z with Z in pattern to use RFC 822 time zone format:
new java.text.SimpleDateFormat("yy/MM/dd,HH:mm:ssZ").parse(str + "00")
// java.util.Date = Sun Jan 26 16:13:13 MSK 2014
java.util.Date (and java.text.SimpleDateFormat) is not the best choice for project. See this answer for some details.
As a bonus DateTimeFormat from Joda-Time allows you to parse your str without modifications:
// I'm using the same pattern with `Z` here
DateTimeFormat.forPattern("yy/MM/dd,HH:mm:ssZ").parseDateTime(str)
// org.joda.time.DateTime = 2014-01-26T16:13:13.000+04:00
If you're looking for "correctness", then don't use SimpleDateFormat!
For one thing, it's not thread safe... and it's silently unsafe, you'll just end up with corrupt dates and no error being thrown. As you're using Scala then it's a fair bet that concurrent programming and thread safety will apply to you.
Use JodaTime, perhaps with one of the Scala wrappers. It gives you some far nicer tools for building date parsers, and generally does the right thing if you simply use the default parser without specifying any format string.