2013-11-06 15:05
浏览 74


I have a date field and a time field which both have their own pickers. One that has the calendar popup and the other has the time popup. Now I have the calendar's format: dd/mm/yyyy now for some reason when I try to save the inputted values i get:

1969-12-31 00:00:00

So I'm not sure what I am doing wrong, I've read every post I've found here on converting string to timestamp and nothing doing. Here's the code I have:

$mydatetime = strip_tags($_POST['datefield']) . ' ' . strip_tags($_POST['timefield']);
$mydatetime = date("Y-m-d H:i:s", strtotime($mydatetime));

any help please?

图片转代码服务由CSDN问答提供 功能建议

我有一个日期字段和一个时间字段,它们都有自己的选择器。 一个具有日历弹出窗口,另一个具有时间弹出窗口。 现在我有日历的格式:dd / mm / yyyy现在出于某种原因我尝试保存输入的值时得到:

  1969-12-31 00:00:  00 

所以我不确定我做错了什么,我已经阅读了我在这里找到的关于将字符串转换为时间戳并且没有做任何事情的帖子。 这是我的代码:

  $ mydatetime = strip_tags($ _ POST ['datefield'])。  ''。  strip_tags($ _ POST ['timefield']); 
 $ mydatetime = date(“Ymd H:i:s”,strtotime($ mydatetime)); 


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douben1891 2013-11-06 15:10


    $mydatetime = str_replace('/','-', strip_tags($_POST['datefield'])) . ' ' 
                    . strip_tags($_POST['timefield']);
    $mydatetime = date("Y-m-d H:i:s", strtotime($mydatetime));

    strtotime waiting format mm/dd/yyyy or dd-mm-yyyy. In your case better transform to dd-mm-yyyy

    打赏 评论
  • duanlujiaji10335 2013-11-06 15:18

    this is the only code you need (anything else is redundant):

        $mydatetime=date('Y-m-d H:i:s', strtotime("$_POST[datefield] $_POST[timefield]"));
    打赏 评论

相关推荐 更多相似问题