dongzaijiao4863 2013-08-19 18:43
浏览 130
已采纳

将PHP回显日期转换为客户端本地时间

This is my first post. I have a problem that i can't seem to resolve. Here it goes:

I have a PHP script that prints the date of an event to the page:

$event_datetime = date("g:i A (m/d/y)", strtotime($row['event_time']));
echo $event_datetime

I want to use Javascript to convert that $event_datetime into client local timezone preferably or local client computer time.

Any ideas ?

Thanks in advance !

  • 写回答

3条回答 默认 最新

  • dpsq8476 2013-08-19 18:50
    关注

    You can use php to convert all dates into a timezone with:

    date_default_timezone_set('America/Los_Angeles');
    

    For example:

    $time = time();
    $date = date(DATE_RFC822, $time);
    echo $date . PHP_EOL;
    
    date_default_timezone_set("Australia/Perth");
    $date = date(DATE_RFC822, $time);
    echo $date. PHP_EOL;
    

    Output:

    Mon, 19 Aug 13 18:49:40 +0000
    Tue, 20 Aug 13 02:49:40 +0800
    

    You would just need to get the clients timezone from somewhere (a preference saved in the database or getting it via javascript for example).

    See Getting the client's timezone in JavaScript for using javascript

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

报告相同问题?

悬赏问题

  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启