dou5454954610 2012-04-27 08:29
浏览 78
已采纳

如何在表单中使用两种日期类型?

Well basically I'm now working on contact form, and I need to add two dates types. User can specify which date they will use in a profile, and then it uses if statement to show exact date type (American or European) in form. That is easy, I can do it with if statement, but next is saving date type to database. Well basically my database table is timestamp, and saving European time is easy, but how about American time? Well basically, in my form for american time there is a hours ( 1 - 12 ), minutes ( 1 - 60) and period ( AM and PM ), well basically 3 select inputs, so any ideas, how could I convert them to 24 hour time and then save to database as European date?

Have done already everything with European date, now only American time left.

Hope you understood what I ment.

  • 写回答

1条回答 默认 最新

  • dptpn06684 2012-04-27 08:41
    关注

    Use DateTime its can convert between any date & time format you want

    $date = DateTime::createFromFormat("m/d/Y","03/32/2012");
    echo $date->format("d-m-Y"); // You can use any format 
    

    OR

    echo $date->format("U"); // Timestamp 
    

    If you want to use functions only

    $date = date_create_from_format("m/d/Y","03/32/2012");
    echo date_format($date, "d-m-Y");
    

    For documentation on different formats : http://www.php.net/manual/en/datetime.createfromformat.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择