0

This code works but when it converts the input into milliseconds it adds five hours. Is there a fix for this?

    ArrayList<String> timeList = new ArrayList<String>();
    Scanner in = new Scanner(System.in);
    System.out.println("Please enter time you arrived (HH:mm:ss): ");
    timeList.add(in.next());
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); 
    String arriveTime = timeList.get(0);
    try{
        Date date1 = format.parse(arriveTime);
        long finalTime = date1.getTime();
    }catch (Exception e) {
        System.out.println("An error occurred");
    }
Arin
  • 1,373
  • 2
  • 10
  • 23
  • possible duplicate of [Java string to date conversion](http://stackoverflow.com/questions/4216745/java-string-to-date-conversion). And [this](http://stackoverflow.com/q/10725246/642706) and [this](http://stackoverflow.com/q/29539404/642706) and many more. – Basil Bourque Jun 19 '15 at 18:00

1 Answers1

3

I'm going to guess you're in the Eastern time zone and are confusing EDT with GMT.

djechlin
  • 59,258
  • 35
  • 162
  • 290