How to parse string to date format in java - java

I have a file file_20201013_012417.txt and I want to validate the timestamp 20201013_012417 format of this file is YYYYMMDD_HHmmSS.
I have tried SimpleDateFormat , but getting java.text.ParseException: Unparseable date execption.
Any help is appreciated.

As I known, you can try to edit the concurrency number for your pipeline at the last step of creating.
Please see the figure below.

Related

Talend timestamp - Getting a zero value instead of timestamp

I am converting string to date using a tConvertType component in Talend.The data(source is in String) is getting loaded when I do the date pattern yyyy-mm-dd but when I try with timestamp yyyy-MM-dd HH:mm:ss then I am getting an error. The data from the source has the timestamp but then I am getting an error.
For Eg : I have the source as 2015-09-03 14:14:90 , since data is in string so used tconverttype and then for destination the data type is date. But if I use timestamp then I am getting an error of Unparseable date and if I change to yyyy-mm-dd then the data is coming as 2015-09-03 00:00:00 which is wrong
try
convert(timestamp,expression)
i had the same problem in the past and convert fixed that
Using the type date and date format "yyyy-MM-dd' 'HH:mm:ss" it works fine
I recommand you to use date format by pressing Ctrl+space and choose from the list.

SQL Server Date time to Salesforce Date in Mule

I have a SQL Server Datetime field with value 1962-04-04 00:00:00.0. This needs to be pushed into Salesforce date field through Mule. I am handling this conversion in the data mapper.
I have tried many possibilities but nothing works. Any pointers would help.
The last one I tried was as below. I thought it should work.
output.PersonBirthdate1 = str2date(input.DATE_OF_BIRTH, "yyyy-MM-dd hh:mm:ss.ZZZ");
But it gives an error:
Caused by: [Error: java.text.ParseException: Unparseable date: "1962-04-04 00:00:00.0"]
Bases on the format of the date,it would be:
str2date(input.DATE_OF_BIRTH,"yyyy-MM-dd HH:mm:ss.S")

JSON parse date and time?

Im having a little issue with parsing json date.
Here is what I would like to parse:
{"driver": "247","firstName": "XXXXX","lastName": "XXXXX","lastLatitudeUpdate": "5/21/2012 4:49:17 PM","suspended": "false","checkedin": "0"}
I am having trouble parsing "lastLatitudeUpdate" is it because there are spaces in between? Thanks in advance for the help.
Assuming you are on Android and therefore working with java (yes you don't mention that, only the tag in your question suggests it...)
Like mentioned here (and in various other places) you can parse a date in java using the SimpleDateFormat class:
SimpleDateFormat parserSDF=new SimpleDateFormat("M/d/yyyy h:m:s a");
Date d = parserSDF.parse(dateField,0);
Of course you have to first parse you json input with some library (e.g. standard library from json.org or Google gson) and then parse the string you'll get there for the field into a date.
Short answer: No, there is no way for the JSON engine to recognize a string as a Date object.
Long answer:
There is no 'date' type in JSON. However, this JSON is fine, the catch is that lastLatitudeUpdate will be parsed as a string. In order to convert this to a date you should try something like
var my_object= JSON.parse({"driver": "247","firstName": "XXXXX","lastName": "XXXXX","lastLatitudeUpdate": "5/21/2012 4:49:17 PM","suspended": "false","checkedin": "0"});
my_object.lastLatitudeUpdate= Date.parse(my_object.lastLatitudeUpdate)
This function will give a timestamp. However, you have to make sure the string is correctly recognized, you may have to do some extra work.
Some links for hints
http://docs.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
http://www.java-samples.com/showtutorial.php?tutorialid=406
How are you parsing the date? In Chrome this seems to work fine:
new Date("5/21/2012 4:49:17 PM");
Mon May 21 2012 16:49:17 GMT-0400 (US Eastern Daylight Time)

Unparseable date with SimpleXml

I am using Simple XML for XML serialization in my Android project. I have problem with parsing a Date object. I receive an exception:
Unparseable date: 2012-05-01T08:22:34+02:00
Can anyone help me how to tell Simple XML what the date format is? Thanks.
SimpleXML only supports some DateFormat's, but you can use a custom Transform for Dates.
Try my example i posted here: Parse date with SimpleFramework
You have a timezone at the end of your date. Java can parse timezone offsets, but without the ยด:' divider between. So if your date timezone were +0200 instead of +02:00, it should work. You could run it through a SimpleDateFormatter.

faced with date parsing problem in jexcel api

I have created a file named tablenew.xls which has date with following code:
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date)formatter.parse(st[length]);
datecell=new DateTime(tokenNumber,lineNumber,date);
sheet.addCell(datecell);
I am getting the output in my file as "04-03-11" which is "dd-MM-yy".
However when this same date is written to another file named tabletemp.xls with the same code , i get the output as something like -689881.5. My dilemma is that the my program however, seems to understand this negative value as a date. Should i modify my code? if so, then what should i do?
thanks in advance
Problem is solved. Thanks anyways. As always, the date "04-03-11" was displayed as
"dd-MM-yy" , was however treated by excel as "MM/dd/yy" .
Jexcel should look into this problem. Their date parsing is a big pain.

Categories