doupishan3309 2012-03-06 20:28
浏览 164
已采纳

Java时间戳和PHP时间戳给出了两个不同的时间

Alright, I can't seem to figure out what is going on, so I have decided to ask you guys. In PHP I am grabbing the UTC timestamp using this code:

date_default_timezone_set("UTC");
time()

This will for example give me 1331065202

Then I have this code in Java to get me the UTC timestamp:

long timestamp = System.currentTimeMillis() / 1000;

This will for example give me 1331093502

Why are the 2 times so different? Shouldn't they both be in UTC Timezone or am I doing something wrong? I am hosted on a VPS and these scrips are on 2 different servers so could it be something on the server side and if so, what can I do?

  • 写回答

3条回答 默认 最新

  • duanshan188866 2012-03-06 20:33
    关注

    Given that the two values are wildly different (not even an integer number of hours), I'd say the clock on one of the machines is wrong. (I'm assuming you took the two timestamps at pretty much the same time.)

    Those timestamps are:

    • PHP: Tue Mar 06 20:20:02 GMT 2012
    • Java: Wed Mar 07 04:11:42 GMT 2012

    Given that it's not March 27th in GMT, it looks like the clock on the Java machine is simply set incorrectly.

    If it's a true VPS that you have complete control over, you should look into using NTP or something similar to keep the servers' clocks correct.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功