gpt4 book ai didi

php - 来自 PHP 的 time() 的 JavaScript 可读日期/时间

转载 作者:IT王子 更新时间:2023-10-29 00:09:57 24 4
gpt4 key购买 nike

是否可以让 JavaScript 计算从 PHP 的 time() 函数返回的时间戳,并以可读的格式显示它,例如“2010 年 4 月 18 日,星期日,下午 4:00”?

最佳答案

使用 Date object这样做:

new Date(<?php echo time(); ?>*1000)

您需要将 Unix 时间戳乘以 1000,因为 Date 期望时间戳以毫秒为单位。

要格式化日期,您可以使用 Date.format method (Date 没有内置)。

关于php - 来自 PHP 的 time() 的 JavaScript 可读日期/时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2658023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com