Java Date Picking Up Wrong Time

Asked

Viewed 73 times

0

Well, I’m having the following problem getting the system time. in a java process I’m working on

I performed the tests at a certain time, and the method below returned 1 hour more

    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
    Date date = new Date();
    java.lang.System.out.println(formatter.format(date));

if I did this 'gambiarra'' in the code it would return the right time

    Date date = new Date();
    Calendar mCalendar = new GregorianCalendar();
    TimeZone timeZone = mCalendar.getTimeZone();
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"+TimeUnit.HOURS.convert(timeZone.getRawOffset(), TimeUnit.MILLISECONDS)));
    java.lang.System.out.println(date.toString());

I was wondering if there’s any way he could show the right time without resorting to that, I think it has something to do with this confusion with the summer time he didn’t have this year

  • I had this problem, on Monday, when some clocks upgraded to summer time, which browser do you use? Mine was Chrome and gave this problem, after updating was normal, picking the correct time.

  • I’m sorry, I didn’t understand the relationship between Chrome and the time I pick up on my file, could explain me better?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.