Convert date between java and .net - 2 days off

前端 未结 3 994
闹比i
闹比i 2021-01-14 17:20

I need to transform a .NET DateTime to an equivalent Java Calendar representation.

The .NET DateTime uses Ticks

3条回答
  •  我在风中等你
    2021-01-14 17:55

    From the Java documentation:

    [...] dates obtained using GregorianCalendar are historically accurate only from March 1, 4 AD onward, when modern Julian calendar rules were adopted

    Considering your DateTime subtraction, it's only a Ticks difference, there is absolutely no notion of a specific calendar here. The implementation is basically return new TimeSpan(x.Ticks - y.Ticks).

    You might be better at simply outputting then parsing an ISO-8061 date/time such as 0001-02-03T00:00:00Z, which has no ambiguity, rather than relying on the internal representation.

提交回复
热议问题