How i can to convert a String to Date?

0
By: Marcelo - mike81
How i can to convert a String to Date?
2003-11-10 08:12
Hi.

How i can to convert a string to date with format "yyyy-mm-dd" without using the Format Pattern?

Thank's.




By: Giulio Toffoli - gt78
RE: How i can to convert a String to Date?
2003-11-10 15:08
if your string is of type...

YYYY-MM-DD you can use an expression like this:


(($P{MyDate} != null && $P{MyDate}.length() == 10) ? $P{MyDate}.substring(8,10)+"/"+$P{MyDate}.substring(6,8)+"/"+$P{MyDate}.substring(0,4) : "")


The result is: DD/MM/YYYY

Enjoy

Giulio
ktrinad's picture
1149
Joined: Aug 9 2006 - 2:36am
Last seen: 12 years 8 months ago

2 Answers:

0
Giulio , this is exactly what I was also looking for. Thanks for this post.
dprogrammer's picture
Joined: Jul 19 2006 - 7:37am
Last seen: 11 months 3 weeks ago
1

I've used the SimpleDateFormat class, might be a little easier if you have mulitple date formats

example:

(new SimpleDateFormat("yyyyMMdd HHmmss")).parse($F{Date})

 

http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html



Post Edited by Austyn Trace at 11/08/08 17:18
atrace's picture
13
Joined: Nov 8 2008 - 9:12am
Last seen: 10 years 5 months ago
Feedback
randomness