使用日期和日期时间到时间

发布于 2024-10-11 16:52:46 字数 542 浏览 5 评论 0原文

我一直在使用以下代码,没有任何问题,直到它最终登陆 Windows 服务器并决定产生错误:

$date = date('F d, Y', $data->e_date)
date($time_format, strtotime($date.' '.$data->e_time))

*(e_date 存储如下:“1293559200”,e_time 存储如下:“18: 00")*

错误如下:

date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in ...

据我了解,这是因为我在日期函数中使用 strtotime。所以我想知道解决或重写这个问题的优雅方法是什么?

我应该将整个 strtotime 输入到一个新变量中,即 $newdate ,然后以该形式返回日期,还是其他方式?

谢谢你!

I've been using the following bit of code without any issues till it finally landed on a windows server and decided to produce an error:

$date = date('F d, Y', $data->e_date)
date($time_format, strtotime($date.' '.$data->e_time))

*(e_date is stored like this: "1293559200", and e_time is stored like this: "18:00")*

The error is as such:

date() [function.date]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in ...

To my understanding this is because I am using strtotime within the date function. So what I'm wondering is what is an elegant method of solving or rewriting this?

Should I be feeding the entire strtotime in a new variable, i.e. $newdate and then back to date in that form, or otherwise?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-10-18 16:52:46

您正在使用 UNIX TIMESTAMP,它将无法在 Windows 操作系统中正常工作。

尝试使用此函数进行转换。
将 20031230233029 转换为 30/12/2003 23:30:59

function mysql_timestamp_para_humano($dt) {
    $yr=strval(substr($dt,0,4));
    $mo=strval(substr($dt,4,2));
    $da=strval(substr($dt,6,2));
    $hr=strval(substr($dt,8,2));
    $mi=strval(substr($dt,10,2));
    $se=strval(substr($dt,12,2)); 
    return date("d/m/Y H:i:s", mktime ($hr,$mi,$se,$mo,$da,$yr));
}

或这个,

function timestamp_para_humano($ts) {
    $d=getdate($ts);
    $yr=$d["year"];
    $mo=$d["mon"];
    $da=$d["mday"];
    $hr=$d["hours"];
    $mi=$d["minutes"];
    $se=$d["seconds"];
    return date("d/m/Y", mktime($hr,$mi,$se,$mo,$da,$yr));
}

或者您可以尝试使用另一个函数将 unix 时间戳转换为 mysql 时间戳

function timestamp_para_mysql_timestamp($ts) {
    $d=getdate($ts);
    $yr=$d["year"];
    $mo=$d["mon"];
    $da=$d["mday"];
    $hr=$d["hours"];
    $mi=$d["minutes"];
    $se=$d["seconds"];
    return sprintf("%04d%02d%02d%02d%02d%02d",$yr,$mo,$da,$hr,$mi,$se);
}

You are using UNIX TIMESTAMP it will not work properly in windows os systems.

Try to convert it using this function.
convert 20031230233029 to 30/12/2003 23:30:59

function mysql_timestamp_para_humano($dt) {
    $yr=strval(substr($dt,0,4));
    $mo=strval(substr($dt,4,2));
    $da=strval(substr($dt,6,2));
    $hr=strval(substr($dt,8,2));
    $mi=strval(substr($dt,10,2));
    $se=strval(substr($dt,12,2)); 
    return date("d/m/Y H:i:s", mktime ($hr,$mi,$se,$mo,$da,$yr));
}

or this one

function timestamp_para_humano($ts) {
    $d=getdate($ts);
    $yr=$d["year"];
    $mo=$d["mon"];
    $da=$d["mday"];
    $hr=$d["hours"];
    $mi=$d["minutes"];
    $se=$d["seconds"];
    return date("d/m/Y", mktime($hr,$mi,$se,$mo,$da,$yr));
}

or you can try to convert the unix timestamp to mysql timestamp wth this another function

function timestamp_para_mysql_timestamp($ts) {
    $d=getdate($ts);
    $yr=$d["year"];
    $mo=$d["mon"];
    $da=$d["mday"];
    $hr=$d["hours"];
    $mi=$d["minutes"];
    $se=$d["seconds"];
    return sprintf("%04d%02d%02d%02d%02d%02d",$yr,$mo,$da,$hr,$mi,$se);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文