佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 885|回复: 19

php 要如何加日期?

[复制链接]
发表于 31-7-2009 09:07 PM | 显示全部楼层 |阅读模式
如题要怎样写?
我要做的是这样,user会key in date 然后再key in 要加多少个月!
当key in 完要加多少个月离开时,会自动 display 加后的 date 出来!!
帮帮忙!!
回复

使用道具 举报


ADVERTISEMENT

发表于 31-7-2009 11:20 PM | 显示全部楼层
date add
回复

使用道具 举报

 楼主| 发表于 31-7-2009 11:38 PM | 显示全部楼层
原帖由 小陈陈 于 31-7-2009 11:20 PM 发表
date add

???
回复

使用道具 举报

发表于 1-8-2009 10:34 PM | 显示全部楼层
看看mktime的function
回复

使用道具 举报

 楼主| 发表于 1-8-2009 10:57 PM | 显示全部楼层
原帖由 lawty 于 1-8-2009 10:34 PM 发表
看看mktime的function


哈哈可以说仔细点吗??
回复

使用道具 举报

 楼主| 发表于 2-8-2009 04:22 PM | 显示全部楼层
没人会吗??
回复

使用道具 举报

Follow Us
发表于 2-8-2009 05:39 PM | 显示全部楼层
表叫人喂你喂到饱饱,自己去找一下 http://www.google.com.tw/search?q=mktime&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

[ 本帖最后由 y小叶y 于 2-8-2009 05:41 PM 编辑 ]
回复

使用道具 举报

发表于 2-8-2009 09:15 PM | 显示全部楼层
mktime(hour, minute, sec, month, day, year)

+ year 的话 mktime(hour, minute, sec, month, day, year+1)

+ day 的话 mktime(hour, minute, sec, month, day+1, year)

研究下吧。。。。
回复

使用道具 举报


ADVERTISEMENT

发表于 2-8-2009 11:39 PM | 显示全部楼层
原帖由 心影 于 31-7-2009 11:38 PM 发表

???



算了。。。
回复

使用道具 举报

发表于 3-8-2009 01:15 AM | 显示全部楼层
oh...抱歉,或许是我的理解能力问题。
对于你的提问我不是很清楚你的问题是问什么,
而且不了解你需要些什么?
所以可能需要你更详细说说你的问题。
如果能,希望你能step by step 表达你的问题,
这样子,大家才比较清楚你问的问题
然后尝试提供不同的解决方案来解答你的问题。

[ 本帖最后由 jinn 于 3-8-2009 01:19 AM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 3-8-2009 09:06 PM | 显示全部楼层
原帖由 jinn 于 3-8-2009 01:15 AM 发表
oh...抱歉,或许是我的理解能力问题。
对于你的提问我不是很清楚你的问题是问什么,
而且不了解你需要些什么?
所以可能需要你更详细说说你的问题。
如果能,希望你能step by step 表达你的问题,
这样子,大家 ...


好的!
1 user会key in date 在textfield
2 user会key in 要加多少个月在另一个textfield
3 当key in 完要加多少个月时会自动display 加起来的date!不需要submit的!

加date的我已经做到了,我是用strtotime
第三step做不到罢了,不会自动display !
回复

使用道具 举报

发表于 3-8-2009 11:19 PM | 显示全部楼层
原帖由 心影 于 3-8-2009 09:06 PM 发表


好的!
1 user会key in date 在textfield
2 user会key in 要加多少个月在另一个textfield
3 当key in 完要加多少个月时会自动display 加起来的date!不需要submit的!

加date的我已经做到了,我是用strtot ...


可以用Java Script来完成
回复

使用道具 举报

发表于 4-8-2009 10:26 AM | 显示全部楼层
看看js 的 DOM programming
回复

使用道具 举报

发表于 4-8-2009 12:10 PM | 显示全部楼层
首先我还不是很清楚你问的问题,
所以不懂以下程式是不是已经回答你的提问。
写了以下程式给你作一些参考。
其实,如果前台设计无需用到大量计算程式,
我想不至于需要用到server language.

用途说明:
  • 界面(interface)显示当前用户电脑时间,并设有两种时间格式让用户输入;一种是以天数计时,另一种是月份计时
  • 当用户在天数的输入框输入了数字,那么系统就会显示从用户输入的数字去推算日期。比如:用户想了解2天后的现在时间是几时,那么用户在天数的输入框输入了2,系统就会显示2天后的时间。
  • 同上,当用户在月数的输入框输入了数字,那么系统就会显示从用户输入的数字去推算日期。唯一不同的是这是与月份来显示时间。


注:
以下的程式只作参考用途。

程式代码
  1. <html>

  2. <head>
  3. <title>Count the time with user key in value</title>
  4. <script language="javascript">
  5. function setT(d,type){
  6.         var myDate = new Date();
  7.         if(d && type ==1) myDate.setDate(myDate.getDate()+parseInt(d));
  8.         if(d && type ==2) myDate.setMonth(myDate.getMonth()+parseInt(d));
  9.         dateString = (myDate.toGMTString()+"
  10. "+myDate.toLocaleString());
  11.         document.getElementById('setTimer').innerHTML = dateString;
  12. }
  13. </script>
  14. </head>

  15. <body>
  16. <div id="setTimer"></div>
  17. <div>
  18. Date :
  19. <input type="text" id="setdate" name="setdate" onkeyup="setT(this.value,1);">

  20. </select>


  21. Month :
  22. <input type="text" id="setmonth" name="setmonth" onkeyup="setT(this.value,2);">

  23. </select>
  24. </div>

  25. <script language="javascript">
  26. setT(0,0);
  27. </script>

  28. </body>

  29. </html>
复制代码

[ 本帖最后由 jinn 于 4-8-2009 12:24 PM 编辑 ]
回复

使用道具 举报

发表于 4-8-2009 12:18 PM | 显示全部楼层
对了,如果要用系统时间(server time)而不是以用户电脑时间为标准,那么就必须改一改程式了。

把这一个
  1. var myDate = new Date();
复制代码
改成
  1. var myDate = new Date(<?= time(); ?> * 1000);
复制代码
回复

使用道具 举报

发表于 4-8-2009 06:18 PM | 显示全部楼层
你应该是要ajax or javascript帮你吧。。不然单是php在用户没有按Button回去server的话,日期是加不到的
回复

使用道具 举报


ADVERTISEMENT

发表于 5-8-2009 03:20 AM | 显示全部楼层
这应该才是你要的吧。。。。。
  1. <html>

  2. <head>
  3. <title>Count the time with user key in value</title>
  4. <script language="javascript">
  5. function setT(d,m){
  6.         var myDate = new Date();
  7.         if(d) {
  8.                 var strArry = d.split('-');
  9.                 myDate.setFullYear(strArry[0],(parseInt(strArry[1])-1),strArry[2]);
  10.         }
  11.         if(m) myDate.setMonth(myDate.getMonth()+parseInt(m));
  12.         dateString = (myDate.toGMTString()+"
  13. "+myDate.toLocaleString());
  14.         document.getElementById('setTimer').innerHTML = dateString;
  15. }
  16. </script>
  17. </head>

  18. <body>
  19. <div id="setTimer"></div>


  20. <div>
  21. Date :
  22. <input type="text" id="setdate" name="setdate"> e.g: YYYY-MM-DD

  23. </select>



  24. Month :
  25. <input type="text" id="setmonth" name="setmonth" onkeyup="setT(document.getElementById('setdate').value,this.value);">

  26. </select>
  27. </div>

  28. <script language="javascript">
  29. setT(0,0);
  30. </script>

  31. </body>

  32. </html>
复制代码
回复

使用道具 举报

 楼主| 发表于 5-8-2009 07:15 PM | 显示全部楼层
原帖由 jinn 于 5-8-2009 03:20 AM 发表
这应该才是你要的吧。。。。。


Count the time with user key in value

function setT(d,m){
        var myDate = new Date();
        if(d) {
                var strArry = d.split('-');
                myDate ...


是我要的了!不过不能display的
回复

使用道具 举报

发表于 14-8-2009 01:52 PM | 显示全部楼层

回复 13# lawty 的帖子

老人?。。。。。。.....
回复

使用道具 举报

发表于 17-8-2009 03:45 AM | 显示全部楼层
参考Date的API。
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 24-5-2024 07:13 AM , Processed in 0.079087 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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