Solved

Parse String 04/26/2010 05:39:26 GMT to Date in Java

Posted on 2009-04-03
7
288 Views
Last Modified: 2013-12-29
Trying to Parse String to Date. I'm getting ParseException.
Calendar timeStamp = Calendar.getInstance(locale);// Date();

			timeStamp.setTime(DateFormat.getDateInstance().parse((String) tokenMap.get("TimeStamp")));

Open in new window

0
Comment
Question by:dolphin_g
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:basav_com
ID: 24063175
Can you print this value.
tokenMap.get("TimeStamp")

--> Seems to be some problem with this.
0
 

Author Comment

by:dolphin_g
ID: 24063190
04/26/2010 05:39:26 GMT
0
 

Author Comment

by:dolphin_g
ID: 24063216
java.text.ParseException: Unparseable date: "04/26/2010 05:39:26 GMT"
      java.text.DateFormat.parse(DateFormat.java:335)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:basav_com
ID: 24063325
Can you print ' locale ' also ?
0
 

Accepted Solution

by:
dolphin_g earned 0 total points
ID: 24063391
Resolved it, by the below code.
Calendar timeStamp = Calendar.getInstance();// Date();

			SimpleDateFormat df = new SimpleDateFormat();

			df.applyPattern("MM/dd/yyyy hh:mm:ss z");

			timeStamp.setTime(df.parse((String) tokenMap.get("TimeStamp")));

Open in new window

0
 
LVL 12

Expert Comment

by:basav_com
ID: 24063409
Great the problem is solved :).

Helpful for others:
Need to 'format with a custom format'
http://www.exampledepot.com/egs/java.text/FormatDateLoc.html?l=rel
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html
0
 
LVL 92

Expert Comment

by:objects
ID: 24064211
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
HashMap Vs TreeMap 12 49
Running Jira on Raspberry PI 2? 3 137
unix in java example 9 43
bitbucket vs gitbucket 3 32
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now