So I'm tring to get a date as a string at the command line and convert it into milliseconds but it keeps adding five hours. Any ideas why?

90 views Asked by At

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");
    }
1

There are 1 answers

1
djechlin On BEST ANSWER

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