在Java中转换Long to Date返回1970年

时间:2022-09-15 18:58:19

I have list with long values (for example: 1220227200, 1220832000, 1221436800...) which I downloaded from web service. I must convert it to Dates. Unfortunately this way, for example:

我有一个长值列表(例如:1220227200,1220832000,1221436800…),我从web service下载的。我必须把它转换成日期。不幸的是,例如:

Date d = new Date(1220227200);

returns 1 Jan 1970. Anyone know another way to convert it correctly?

返回1 1970年1月。有人知道另一种正确转换的方法吗?

10 个解决方案

#1


118  

The Date constructor (click the link!) accepts the time as long in milliseconds, not seconds. You need to multiply it by 1000 and make sure that you supply it as long.

日期构造函数(单击链接!)接受时间的长度为毫秒,而不是秒。你需要将它乘以1000,并确保你供给它的时间足够长。

Date d = new Date(1220227200L * 1000);

This shows here

这显示了

Sun Aug 31 20:00:00 GMT-04:00 2008

2008年8月31日20:00 GMT-04:00

#2


36  

tl;dr

Instant.ofEpochSecond( 1_220_227_200L )

Know Your Data

People use various precisions in tracking time as a number since an epoch. So when you obtain some numbers to be interpreted as a count since an epoch, you must determine:

人们用不同的精确值来跟踪一个时代以来的时间。因此,当你得到一些从一个时期开始被解释为计数的数字时,你必须确定:

  • What epoch?
    Many epochs dates have been used in various systems. Commonly used is POSIX/Unix time, where the epoch is the first moment of 1970 in UTC. But you should not assume this epoch.
  • 什么时代?许多划时代的日期在不同的系统中被使用。通常使用的是POSIX/Unix时间,在UTC中,纪元时间是1970年的第一个时刻。但你不应该假设这个时代。
  • What precision?
    Are we talking seconds, milliseconds, microseconds, or nanoseconds since the epoch?
  • 精度是什么?我们说的是秒,毫秒,微秒,还是从纪元以来的纳秒?
  • What time zone?
    Usually a count since epoch is in UTC/GMT time zone, that is, has no time zone offset at all. But sometimes, when involving inexperienced or date-time ignorant programmers, there may be an implied time zone.
  • 什么时区?通常来说,从纪元以来的计数是在UTC/GMT时区,也就是说,没有时区偏移。但有时,当涉及到缺乏经验或不了解日期时间的程序员时,可能存在一个隐含的时区。

In your case, as others noted, you seem to have been given seconds since the Unix epoch. But you are passing those seconds to a constructor that expects milliseconds. So the solution is to multiply by 1,000.

在您的例子中,正如其他人所指出的,您似乎已经从Unix纪元中获得了几秒钟的时间。但是,您正在将这些秒传递给期望毫秒的构造函数。所以解是乘以1000。

Lessons learned:

经验教训:

  • Determine, don't assume, the meaning of received data.
  • 确定接收数据的含义,不要假设。
  • Read the doc.
  • 看医生。

在Java中转换Long to Date返回1970年

Your Data

Your data seems to be in whole seconds. If we assume an epoch of the beginning of 1970, and if we assume UTC time zone, then 1,220,227,200 is the first moment of the first day of September 2008.

你的数据似乎在几秒钟之内。如果我们假设一个1970年开始的时代,如果我们假设UTC时区,那么1220,227,200是2008年9月第一天的第一个时刻。

Joda-Time

The java.util.Date and .Calendar classes bundled with Java are notoriously troublesome. Avoid them. Use instead either the Joda-Time library or the new java.time package bundled in Java 8 (and inspired by Joda-Time).

java.util。与Java绑定的日期和. calendar类是出了名的麻烦。避免它们。而是使用Joda-Time库或新的java。在Java 8中绑定的时间包(受到Joda-Time的启发)。

Note that unlike j.u.Date, a DateTime in Joda-Time truly knows its own assigned time zone. So in the example Joda-Time 2.4 code seen below, note that we first parse the milliseconds using the default assumption of UTC. Then, secondly, we assign a time zone of Paris to adjust. Same moment in the timeline of the Universe, but different wall-clock time. For demonstration, we adjust again, to UTC. Almost always better to explicitly specify your desired/expected time zone rather than rely on an implicit default (often the cause of trouble in date-time work).

注意,不像j.u。Date, Joda-Time中的一个DateTime真正知道它自己分配的时区。因此,在下面的示例Joda-Time 2.4代码中,请注意,我们首先使用UTC的默认假设解析毫秒数。其次,我们指定巴黎的时区进行调整。宇宙时间轴上同样的时刻,但不同的时钟时间。为了演示,我们再次调整到UTC。几乎总是最好明确指定所需的/预期的时区,而不是依赖于隐式的默认值(通常是日期-时间工作中出现问题的原因)。

We need milliseconds to construct a DateTime. So take your input of seconds, and multiply by a thousand. Note that the result must be a 64-bit long as we would overflow a 32-bit int.

我们需要毫秒来构建一个DateTime。所以,输入你的秒数,乘以1000。注意,结果必须是64位的,因为我们会溢出一个32位的整数。

long input = 1_220_227_200L;  // Note the "L" appended to long integer literals.long milliseconds = ( input * 1_000L ); // Use a "long", not the usual "int". Note the appended "L".

Feed that count of milliseconds to constructor. That particular constructor assumes the count is from the Unix epoch of 1970. So adjust time zone as desired, after construction.

向构造函数提供毫秒数。该构造函数假定计数来自1970年的Unix纪元。所以在施工后,根据需要调整时区。

Use proper time zone names, a combination of continent and city/region. Never use 3 or 4 letter codes such as EST as they are neither standardized not unique.

使用合适的时区名称,一个大陆和城市/地区的组合。不要使用像EST这样的3或4个字母代码,因为它们不是标准化的,也不是唯一的。

DateTime dateTimeParis = new DateTime( milliseconds ).withZone( DateTimeZone.forID( "Europe/Paris" ) );

For demonstration, adjust the time zone again.

为了演示,再次调整时区。

DateTime dateTimeUtc = dateTimeParis.withZone( DateTimeZone.UTC );DateTime dateTimeMontréal = dateTimeParis.withZone( DateTimeZone.forID( "America/Montreal" ) );

Dump to console. Note how the date is different in Montréal, as the new day has begun in Europe but not yet in America.

转储到控制台。请注意蒙特利尔的日期是如何不同的,因为新的一天在欧洲开始,但在美国还没有。

System.out.println( "dateTimeParis: " + dateTimeParis );System.out.println( "dateTimeUTC: " + dateTimeUtc );System.out.println( "dateTimeMontréal: " + dateTimeMontréal );

When run.

运行时。

dateTimeParis: 2008-09-01T02:00:00.000+02:00dateTimeUTC: 2008-09-01T00:00:00.000ZdateTimeMontréal: 2008-08-31T20:00:00.000-04:00

java.time

The makers of Joda-Time have asked us to migrate to its replacement, the java.time framework as soon as is convenient. While Joda-Time continues to be actively supported, all future development will be done on the java.time classes and their extensions in the ThreeTen-Extra project.

Joda-Time的制造商要求我们迁移到它的替代品java。时间框架只要方便。虽然Joda-Time仍然受到积极支持,但所有未来的开发都将在java上完成。时间类及其扩展在三个额外的项目中。

The java-time framework is defined by JSR 310 and built into Java 8 and later. The java.time classes have been back-ported to Java 6 & 7 on the ThreeTen-Backport project and to Android in the ThreeTenABP project.

Java -time框架由JSR 310定义,并内置到Java 8和以后的版本中。java。time类在three - backport项目中被反向移植到Java 6和7,在ThreeTenABP项目中被移植到Android上。

An Instant is a moment on the timeline in UTC with a resolution of nanoseconds. Its epoch is the first moment of 1970 in UTC.

瞬间是UTC时间轴上的时刻,分辨率为纳秒。它的时代是1970年UTC的第一个时刻。

Instant instant = Instant.ofEpochSecond( 1_220_227_200L );

Apply an offset-from-UTC ZoneOffset to get an OffsetDateTime.

应用offset-from-UTC ZoneOffset获得OffsetDateTime。

Better yet, if known, apply a time zone ZoneId to get a ZonedDateTime.

更好的是,如果知道的话,应用一个时区ZoneId来获得一个时区。

ZoneId zoneId = ZoneId.of( "America/Montreal" );ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId );

#3


35  

It looks like your longs are seconds, and not milliseconds. Date constructor takes time as millis, so

看起来你的渴望是秒,而不是毫秒。Date构造函数使用时间作为millis,所以

Date d = new Date(timeInSeconds * 1000);

#4


8  

Those are probably timestamps in seconds and not in milliseconds which is required for the java new Date(long) constructor. Just multiply them by 1000 and you should be allright.

这些时间戳可能以秒为单位,而不是以毫秒为单位,这是java new Date(long)构造函数所需要的。只要把它们乘以1000就行了。

#5


7  

Only set the time in mills on Calendar object

只在日历对象上的mills中设置时间

Calendar c = Calendar.getInstance();c.setTimeInMillis(1385355600000l);System.out.println(c.get(Calendar.YEAR));System.out.println(c.get(Calendar.MONTH));System.out.println(c.get(Calendar.DAY_OF_MONTH));// get DateSystem.out.println(c.getTime());

#6


3  

Try this:

试试这个:

Calendar cal = Calendar.getInstance();cal.setTimeInMillis(1220227200 * 1000);System.out.println(cal.getTime());

#7


3  

The long values, most likely, correspond to Epoch timestamps, and the values are:

长值很可能与历元时间戳对应,其值为:

1220227200 = Mon, 01 Sep 2008 00:00:00 GMT

1220227200 = Mon, 2008年9月1日格林尼治时间。

1220832000 = Mon, 08 Sep 2008 00:00:00 GMT

1220832000 = Mon, 08 Sep 2008 00:00:00 GMT

1221436800 = Mon, 15 Sep 2008 00:00:00 GMT

1221436800 = Mon, 9月15日00:00:00 GMT

One can convert these long values to java.util.Date, taking into account the fact java.util.Date uses millisecs – as previously hinted, but with some flaw - like this:

可以将这些长值转换为java.util。日期,考虑到java.util这一事实。日期使用毫秒——如前所述,但有一些缺陷——像这样:

// note: enforcing long literals (L), without it the values would just be wrong.Date date = new Date(1220227200L * 1000L); 

Now, to display the date correctly, one can use java.text.DateFormat as illustrated hereafter:

现在,要正确显示日期,可以使用java.text。DateFormat如以下所示:

DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);df.setTimeZone(TimeZone.getTimeZone("UTC"));System.out.println("Wrong date time value: " + date);System.out.println("Correct date time value: " + df.format(date));

Below are the results of displaying the converted long value to java.util.Date without using and using the DateFormat:

下面是向java.util显示转换后的长值的结果。不使用和使用日期格式的日期:

Date wrong (off by 2 hours): Mon Sep 01 02:00:00 CEST 2008Correct date : Monday, 1 September 2008 00:00:00 o'clock UTC

#8


1  

1220227200 corresponds to Jan 15 1980 (and indeed new Date(1220227200).toString() returns "Thu Jan 15 03:57:07 CET 1970"). If you pass a long value to a date, that is before 01/01/1970 it will in fact return a date of 01/01/1970. Make sure that your values are not in this situation (lower than 82800000).

1220227200对应于1980年1月15日(实际上是新的日期(1220227200). tostring()返回“Thu Jan 15 03:57:07 CET 1970”)。如果你将一个长值传递给一个日期,那是在01/01/1970之前,它实际上会返回一个日期01/01/1970。确保您的值不在这种情况下(低于82800000)。

#9


0  

New Date(number) returns a date that's number milliseconds after 1 Jan 1970. Odds are you date format isn't showing hours, minutes, and seconds for you to see that it's just a little bit after 1 Jan 1970.

New Date(number)返回的日期是1970年1月1日之后的毫秒数。很有可能你的日期格式没有显示小时,分钟和秒,你会发现它只是在1970年1月1日之后。

You need to parse the date according to the correct parsing routing. I don't know what a 1220227200 is, but if it's seconds after 1 JAN 1970, then multiply it to yield milliseconds. If it is not, then convert it in some manner to milliseconds after 1970 (if you want to continue to use java.util.Date).

您需要根据正确的解析路由解析日期。我不知道1220227200是多少,但是如果是1970年1月1日之后的几秒,那么乘以它,得到毫秒数。如果不是,那么在1970年后以某种方式将其转换为毫秒(如果您想继续使用java.util.Date)。

#10


0  

Works for me. You probably want to multiplz it with 1000, since what you get are the seconds from 1970 and you have to pass the milliseconds from jan 1 1970

为我工作。你可能想要用1000多倍plz,因为你得到的是1970年的秒,而你必须通过1970年1月1日的毫秒

#1


118  

The Date constructor (click the link!) accepts the time as long in milliseconds, not seconds. You need to multiply it by 1000 and make sure that you supply it as long.

日期构造函数(单击链接!)接受时间的长度为毫秒,而不是秒。你需要将它乘以1000,并确保你供给它的时间足够长。

Date d = new Date(1220227200L * 1000);

This shows here

这显示了

Sun Aug 31 20:00:00 GMT-04:00 2008

2008年8月31日20:00 GMT-04:00

#2


36  

tl;dr

Instant.ofEpochSecond( 1_220_227_200L )

Know Your Data

People use various precisions in tracking time as a number since an epoch. So when you obtain some numbers to be interpreted as a count since an epoch, you must determine:

人们用不同的精确值来跟踪一个时代以来的时间。因此,当你得到一些从一个时期开始被解释为计数的数字时,你必须确定:

  • What epoch?
    Many epochs dates have been used in various systems. Commonly used is POSIX/Unix time, where the epoch is the first moment of 1970 in UTC. But you should not assume this epoch.
  • 什么时代?许多划时代的日期在不同的系统中被使用。通常使用的是POSIX/Unix时间,在UTC中,纪元时间是1970年的第一个时刻。但你不应该假设这个时代。
  • What precision?
    Are we talking seconds, milliseconds, microseconds, or nanoseconds since the epoch?
  • 精度是什么?我们说的是秒,毫秒,微秒,还是从纪元以来的纳秒?
  • What time zone?
    Usually a count since epoch is in UTC/GMT time zone, that is, has no time zone offset at all. But sometimes, when involving inexperienced or date-time ignorant programmers, there may be an implied time zone.
  • 什么时区?通常来说,从纪元以来的计数是在UTC/GMT时区,也就是说,没有时区偏移。但有时,当涉及到缺乏经验或不了解日期时间的程序员时,可能存在一个隐含的时区。

In your case, as others noted, you seem to have been given seconds since the Unix epoch. But you are passing those seconds to a constructor that expects milliseconds. So the solution is to multiply by 1,000.

在您的例子中,正如其他人所指出的,您似乎已经从Unix纪元中获得了几秒钟的时间。但是,您正在将这些秒传递给期望毫秒的构造函数。所以解是乘以1000。

Lessons learned:

经验教训:

  • Determine, don't assume, the meaning of received data.
  • 确定接收数据的含义,不要假设。
  • Read the doc.
  • 看医生。

在Java中转换Long to Date返回1970年

Your Data

Your data seems to be in whole seconds. If we assume an epoch of the beginning of 1970, and if we assume UTC time zone, then 1,220,227,200 is the first moment of the first day of September 2008.

你的数据似乎在几秒钟之内。如果我们假设一个1970年开始的时代,如果我们假设UTC时区,那么1220,227,200是2008年9月第一天的第一个时刻。

Joda-Time

The java.util.Date and .Calendar classes bundled with Java are notoriously troublesome. Avoid them. Use instead either the Joda-Time library or the new java.time package bundled in Java 8 (and inspired by Joda-Time).

java.util。与Java绑定的日期和. calendar类是出了名的麻烦。避免它们。而是使用Joda-Time库或新的java。在Java 8中绑定的时间包(受到Joda-Time的启发)。

Note that unlike j.u.Date, a DateTime in Joda-Time truly knows its own assigned time zone. So in the example Joda-Time 2.4 code seen below, note that we first parse the milliseconds using the default assumption of UTC. Then, secondly, we assign a time zone of Paris to adjust. Same moment in the timeline of the Universe, but different wall-clock time. For demonstration, we adjust again, to UTC. Almost always better to explicitly specify your desired/expected time zone rather than rely on an implicit default (often the cause of trouble in date-time work).

注意,不像j.u。Date, Joda-Time中的一个DateTime真正知道它自己分配的时区。因此,在下面的示例Joda-Time 2.4代码中,请注意,我们首先使用UTC的默认假设解析毫秒数。其次,我们指定巴黎的时区进行调整。宇宙时间轴上同样的时刻,但不同的时钟时间。为了演示,我们再次调整到UTC。几乎总是最好明确指定所需的/预期的时区,而不是依赖于隐式的默认值(通常是日期-时间工作中出现问题的原因)。

We need milliseconds to construct a DateTime. So take your input of seconds, and multiply by a thousand. Note that the result must be a 64-bit long as we would overflow a 32-bit int.

我们需要毫秒来构建一个DateTime。所以,输入你的秒数,乘以1000。注意,结果必须是64位的,因为我们会溢出一个32位的整数。

long input = 1_220_227_200L;  // Note the "L" appended to long integer literals.long milliseconds = ( input * 1_000L ); // Use a "long", not the usual "int". Note the appended "L".

Feed that count of milliseconds to constructor. That particular constructor assumes the count is from the Unix epoch of 1970. So adjust time zone as desired, after construction.

向构造函数提供毫秒数。该构造函数假定计数来自1970年的Unix纪元。所以在施工后,根据需要调整时区。

Use proper time zone names, a combination of continent and city/region. Never use 3 or 4 letter codes such as EST as they are neither standardized not unique.

使用合适的时区名称,一个大陆和城市/地区的组合。不要使用像EST这样的3或4个字母代码,因为它们不是标准化的,也不是唯一的。

DateTime dateTimeParis = new DateTime( milliseconds ).withZone( DateTimeZone.forID( "Europe/Paris" ) );

For demonstration, adjust the time zone again.

为了演示,再次调整时区。

DateTime dateTimeUtc = dateTimeParis.withZone( DateTimeZone.UTC );DateTime dateTimeMontréal = dateTimeParis.withZone( DateTimeZone.forID( "America/Montreal" ) );

Dump to console. Note how the date is different in Montréal, as the new day has begun in Europe but not yet in America.

转储到控制台。请注意蒙特利尔的日期是如何不同的,因为新的一天在欧洲开始,但在美国还没有。

System.out.println( "dateTimeParis: " + dateTimeParis );System.out.println( "dateTimeUTC: " + dateTimeUtc );System.out.println( "dateTimeMontréal: " + dateTimeMontréal );

When run.

运行时。

dateTimeParis: 2008-09-01T02:00:00.000+02:00dateTimeUTC: 2008-09-01T00:00:00.000ZdateTimeMontréal: 2008-08-31T20:00:00.000-04:00

java.time

The makers of Joda-Time have asked us to migrate to its replacement, the java.time framework as soon as is convenient. While Joda-Time continues to be actively supported, all future development will be done on the java.time classes and their extensions in the ThreeTen-Extra project.

Joda-Time的制造商要求我们迁移到它的替代品java。时间框架只要方便。虽然Joda-Time仍然受到积极支持,但所有未来的开发都将在java上完成。时间类及其扩展在三个额外的项目中。

The java-time framework is defined by JSR 310 and built into Java 8 and later. The java.time classes have been back-ported to Java 6 & 7 on the ThreeTen-Backport project and to Android in the ThreeTenABP project.

Java -time框架由JSR 310定义,并内置到Java 8和以后的版本中。java。time类在three - backport项目中被反向移植到Java 6和7,在ThreeTenABP项目中被移植到Android上。

An Instant is a moment on the timeline in UTC with a resolution of nanoseconds. Its epoch is the first moment of 1970 in UTC.

瞬间是UTC时间轴上的时刻,分辨率为纳秒。它的时代是1970年UTC的第一个时刻。

Instant instant = Instant.ofEpochSecond( 1_220_227_200L );

Apply an offset-from-UTC ZoneOffset to get an OffsetDateTime.

应用offset-from-UTC ZoneOffset获得OffsetDateTime。

Better yet, if known, apply a time zone ZoneId to get a ZonedDateTime.

更好的是,如果知道的话,应用一个时区ZoneId来获得一个时区。

ZoneId zoneId = ZoneId.of( "America/Montreal" );ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId );

#3


35  

It looks like your longs are seconds, and not milliseconds. Date constructor takes time as millis, so

看起来你的渴望是秒,而不是毫秒。Date构造函数使用时间作为millis,所以

Date d = new Date(timeInSeconds * 1000);

#4


8  

Those are probably timestamps in seconds and not in milliseconds which is required for the java new Date(long) constructor. Just multiply them by 1000 and you should be allright.

这些时间戳可能以秒为单位,而不是以毫秒为单位,这是java new Date(long)构造函数所需要的。只要把它们乘以1000就行了。

#5


7  

Only set the time in mills on Calendar object

只在日历对象上的mills中设置时间

Calendar c = Calendar.getInstance();c.setTimeInMillis(1385355600000l);System.out.println(c.get(Calendar.YEAR));System.out.println(c.get(Calendar.MONTH));System.out.println(c.get(Calendar.DAY_OF_MONTH));// get DateSystem.out.println(c.getTime());

#6


3  

Try this:

试试这个:

Calendar cal = Calendar.getInstance();cal.setTimeInMillis(1220227200 * 1000);System.out.println(cal.getTime());

#7


3  

The long values, most likely, correspond to Epoch timestamps, and the values are:

长值很可能与历元时间戳对应,其值为:

1220227200 = Mon, 01 Sep 2008 00:00:00 GMT

1220227200 = Mon, 2008年9月1日格林尼治时间。

1220832000 = Mon, 08 Sep 2008 00:00:00 GMT

1220832000 = Mon, 08 Sep 2008 00:00:00 GMT

1221436800 = Mon, 15 Sep 2008 00:00:00 GMT

1221436800 = Mon, 9月15日00:00:00 GMT

One can convert these long values to java.util.Date, taking into account the fact java.util.Date uses millisecs – as previously hinted, but with some flaw - like this:

可以将这些长值转换为java.util。日期,考虑到java.util这一事实。日期使用毫秒——如前所述,但有一些缺陷——像这样:

// note: enforcing long literals (L), without it the values would just be wrong.Date date = new Date(1220227200L * 1000L); 

Now, to display the date correctly, one can use java.text.DateFormat as illustrated hereafter:

现在,要正确显示日期,可以使用java.text。DateFormat如以下所示:

DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);df.setTimeZone(TimeZone.getTimeZone("UTC"));System.out.println("Wrong date time value: " + date);System.out.println("Correct date time value: " + df.format(date));

Below are the results of displaying the converted long value to java.util.Date without using and using the DateFormat:

下面是向java.util显示转换后的长值的结果。不使用和使用日期格式的日期:

Date wrong (off by 2 hours): Mon Sep 01 02:00:00 CEST 2008Correct date : Monday, 1 September 2008 00:00:00 o'clock UTC

#8


1  

1220227200 corresponds to Jan 15 1980 (and indeed new Date(1220227200).toString() returns "Thu Jan 15 03:57:07 CET 1970"). If you pass a long value to a date, that is before 01/01/1970 it will in fact return a date of 01/01/1970. Make sure that your values are not in this situation (lower than 82800000).

1220227200对应于1980年1月15日(实际上是新的日期(1220227200). tostring()返回“Thu Jan 15 03:57:07 CET 1970”)。如果你将一个长值传递给一个日期,那是在01/01/1970之前,它实际上会返回一个日期01/01/1970。确保您的值不在这种情况下(低于82800000)。

#9


0  

New Date(number) returns a date that's number milliseconds after 1 Jan 1970. Odds are you date format isn't showing hours, minutes, and seconds for you to see that it's just a little bit after 1 Jan 1970.

New Date(number)返回的日期是1970年1月1日之后的毫秒数。很有可能你的日期格式没有显示小时,分钟和秒,你会发现它只是在1970年1月1日之后。

You need to parse the date according to the correct parsing routing. I don't know what a 1220227200 is, but if it's seconds after 1 JAN 1970, then multiply it to yield milliseconds. If it is not, then convert it in some manner to milliseconds after 1970 (if you want to continue to use java.util.Date).

您需要根据正确的解析路由解析日期。我不知道1220227200是多少,但是如果是1970年1月1日之后的几秒,那么乘以它,得到毫秒数。如果不是,那么在1970年后以某种方式将其转换为毫秒(如果您想继续使用java.util.Date)。

#10


0  

Works for me. You probably want to multiplz it with 1000, since what you get are the seconds from 1970 and you have to pass the milliseconds from jan 1 1970

为我工作。你可能想要用1000多倍plz,因为你得到的是1970年的秒,而你必须通过1970年1月1日的毫秒