Home  >  Article  >  Backend Development  >  java 时间戳跟PHP时间戳 的转换 php time()

java 时间戳跟PHP时间戳 的转换 php time()

WBOY
WBOYOriginal
2016-06-13 11:43:23924browse

java 时间戳和PHP时间戳 的转换 php time()

总结一下java 时间戳和PHP时间戳 的转换问题: 由于精度不同,导致长度不一致,直接转换错误。
JAVA时间戳长度是13位,如:1294890876859 PHP时间戳长度是10位, 如:1294890859
主要最后三位的不同,JAVA时间戳在PHP中使用,去掉后三位,如:1294890876859-> 1294890876 结果:2011-01-13 11:54:36

  1. echo date('Y-m-d H:i:s','1294890876');

  PHP时间戳在JAVA中使用,最后加三位,用000补充,如:1294890859->1294890859000
  结果:2011-01-13 11:54:19

  1. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  2. String dateTime = df.format(1294890859000L);???????????????
  3. System.out.println(df);

总结一下java时间戳和PHP时间戳 的转换问题:
由于精度不同,导致长度不一致,直接转换错误。 JAVA时间戳长度是13位,如:1294890876859 PHP时间戳长度是10位, 如:1294890859
主要最后三位的不同,JAVA时间戳在PHP中使用,去掉后三位,如:1294890876859-> 1294890876 结果:2011-01-13 11:54:36 echo date('Y-m-d H:i:s','1294890876'); PHP时间戳在JAVA中使用,最后加三位,用000补充,如:1294890859->1294890859000
结果:2011-01-13 11:54:19 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateTime = df.format(1294890859000L);???????????????

System.out.println(df);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn