views:

2045

answers:

3

Hi,

I used following code to convert string to date but it is applying timezone of device while conversion.
I don't need this but I want same date/time from that string like

String = "2009-07-31 07:59:17.427"
Date = 2009-07-31 07:59:17.427

Date formatter = new Date(HttpDateParser.parse("2009-07-31 07:59:17.427"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String strCustomDateTime = dateFormat.format(formatter);
+1  A: 

What is the problem, exactly? You are trying to convert "2009-07-31 07:59:17.427" into a point in time, but, this does not specify a unique point in time -- without a timezone. So you do need a timezone, and the library is necessary picking one, the platform's current timezone.

If the problem is you wish to specify a different time zone, then call DateFormat.setTimeZone():

format.setTimeZone(TimeZone.getTimeZone("your time zone"));
Sean Owen
I get an error for the setTimeZone method in Blackberry. I just want to get the Date representation which is string format to the date format as is.
Neo
+1  A: 

You may take in account default timezone offset to date you get after parsing:

public static String StringToDate(String dateToParse) {

 Date formatter = new Date(HttpDateParser.parse(dateToParse));
 SimpleDateFormat dateFormat = new SimpleDateFormat(
   "yyyy-MM-dd HH:mm:ss.SSS");
 int offset = TimeZone.getDefault().getRawOffset();
 formatter.setTime(formatter.getTime() + offset);
 String strCustomDateTime = dateFormat.format(formatter);
 return strCustomDateTime;
}
Max Gontar
A: 

I have the date format like yyyy/MM/dd. How to parse this format in blackberry. Thanks

Jasbeer