找回密码
 注-册

QQ登录

只需一步,快速开始

查看: 2219|回复: 0

[PHP] PHP格式的UNIX时间戳转换为Javascript

[复制链接]
Leya 发表于 2010-1-1 02:41:54 | 显示全部楼层 |阅读模式
  1. <?
  2. echo "本机所在的时区:".date("T")."<BR>";
  3. echo "PHP时间戳(UNIX秒):".mktime()."<BR>";
  4. echo "PHP时间(本地格式化后):".date("Y-m-d H:i:s")."<HR>";
  5. ?>
  6. <script language="">
  7. <!--
  8. var d;
  9. function myDate(timestamp) {
  10. d = new Date(timestamp);
  11. var jstimestamp = (d.getFullYear())+"-"+(d.getMonth()+1)+"-"+(d.getDate())+" "+(d.getHours())+":"+(d.getMinutes())+":"+(d.getSeconds());
  12. return jstimestamp;
  13. }
  14. var phptimestamp = <?=mktime()?>;
  15. var jstimestamp = myDate((phptimestamp*1000));
  16.   
  17. document.writeln("PHP传递给时间:" + phptimestamp + "<BR>");
  18. alert("PHP传递给时间:" + phptimestamp);
  19.   
  20. document.writeln("将PHP传递来的时间乘以1000后的时间戳:" + phptimestamp*1000 + "<BR>");
  21. alert("将PHP传递来的时间乘以1000后的时间戳:" + phptimestamp*1000);
  22.   
  23. document.writeln("自身格式化PHP传递来乘以1000后的时间戳:" + d + "<BR>");
  24. alert("自身格式化PHP传递来乘以1000后的时间戳:" + d);
  25.   
  26. document.writeln("转换后的时间:" + jstimestamp + "<BR>");
  27. alert("转换后的时间:" + jstimestamp);
  28. //-->
  29. </script>

复制代码
  1.    //计算日期的前N天或后N天,   
  2.   function   post_date($date,   $days)   {   
  3.   $t1   =   strtotime($date);   
  4.   $t2   =   $t1   -   $days*3600*24;   
  5.   return   date("Y-m-d",   $t2);   
  6.   }   
  7.   echo   post_date(date("Y-m-d"),2), "昨天的昨天<br>";
  8.   echo   post_date(date("Y-m-d"),1), "昨天<br>";
  9.   echo   post_date(date("Y-m-d"),0), "今天<br>"   ;
  10.   echo   post_date(date("Y-m-d"),-1), "明天<br>"   ;
  11.   echo   post_date(date("Y-m-d"),-2), "明天的明天<br>";
复制代码
  1.   echo   '方案1:'.date("Y-m-d",strtotime("+1   day"))."<br>";   
  2.   echo   '方案2:'.date("Y-m-d",time()+3600*24)."<br>";  
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注-册

本版积分规则

Archiver|手机版|小黑屋|DoDVip ( 桂ICP备14000730号 )

GMT+8, 2025-6-17 07:43 , Processed in 0.038708 second(s), 21 queries .

Powered by Discuz! X3.5

Copyright © 2001-2025 Tencent Cloud.

快速回复 返回顶部 返回列表