0

Im converting long value into Date using new Date(long) for the same value my local machine gives

Long Value:- 1481394600000

Date:- 2016-12-11 (Actual value)

Date:- 2016-12-10 (I get this)

However, I get proper value in my local setup. But Remote machine gives one day less. Both the machines are in UTC time zone.

syv
  • 3,528
  • 7
  • 35
  • 50
  • 2
    I get the same value as you (10/12). Can you post your code? Also are you using java.util.Date? – dahui Oct 12 '16 at 16:09
  • Please search Stack Overflow before posting. This has been covered many times already. Tip: search for java.time milliseconds epoch Instant ZonedDateTime – Basil Bourque Oct 12 '16 at 16:31

1 Answers1

1

On my local computer to run:

import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

public class Test {

    public static void main(String[] args) {

        LocalDateTime dateTime = LocalDateTime.of(2016, Month.DECEMBER, 11, 12, 30);
        ZonedDateTime zdt = dateTime.atZone(ZoneOffset.UTC);

        String dataInUTC = zdt.toString();
        System.out.println(dataInUTC);
    }
}

Result:

2016-12-11T12:30Z

Maybe you should use the LocalDateTime and ZoneDateTime

Grzesiek
  • 715
  • 5
  • 24