Convert strings to Blackberry Java today

I used the following code to convert a string to a date, but applies the device time zone when converting.
I do not need this, but I need the same date / time from this line as

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);
+3
source share
2 answers

You can accept the default timezone offset that you received 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;
}
+6
source

, ? "2009-07-31 07: 59: 17.427" , - . , , , .

, , DateFormat.setTimeZone():

format.setTimeZone(TimeZone.getTimeZone("your time zone"));
+1

Source: https://habr.com/ru/post/1714039/


All Articles