1

I need to convert timestamp string to long.
Here is my input string:

2016-08-10T11:24:57.182+0300

here is code witch I am trying to use for converting:

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.sssZ");
        try {
            Date date = simpleDateFormat.parse(timestamp);

            long time = date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }

result: 1470817622000

but when i check this long time here, it returns me this string:

10 august 2016 8:27:02 GMT

but this is different from the input string.
any idea why it happens and how to fix this?

Ulf Gjerdingen
  • 1,414
  • 3
  • 16
  • 20
Andriy Antonov
  • 1,360
  • 2
  • 15
  • 29
  • 1
    What do you mean different from the input string? Your input is GMT+0300. – Unknown Aug 10 '16 at 07:59
  • Whats the java version you are using? The `Z` is only supported from java-7 upwards. [also see this question](http://stackoverflow.com/questions/2580925/simpledateformat-parsing-date-with-z-literal) – SomeJavaGuy Aug 10 '16 at 08:05
  • @KevinEsche Refer https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html We can use Z in Java 6 also. – Unknown Aug 10 '16 at 08:13
  • @Andriy Antonov: You are getting the correct output 10 august 2016 8:27:02 GMT ~= 2016-08-10T11:24:57.182+0300 (I used equivalent sign since there is few minutes of difference) – Unknown Aug 10 '16 at 08:21
  • @Unknown, yep, looks like. but i need to convert that time according with the timezone – Andriy Antonov Aug 10 '16 at 11:14

0 Answers0