将日期时间转换回原始格式 [英] Converting a datetime back to the original format

查看:180
本文介绍了将日期时间转换回原始格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了这段代码

$new_date = date('Y-m-d H:i:s', timetostr($orig_date));

将此输入转换为 2010年6月2日星期三 datetime 输出 2010-06-02 00:00:00

to convert this input Wed Jun 2 2010 to a datetime output 2010-06-02 00:00:00

当我从数据库中读取它时,如何将其转换回 2010年6月2日星期三的原始格式?

When I read it from the database, how do I convert it back to the original format of Wed Jun 2 2010?

推荐答案

您可以使用函数 strftime()(请参见 php.net手册:strftime()了解更多信息和所有参数),并带有指定参数可以将时间戳转换回人类可读的格式。

You can use the function strftime() (see php.net manual: strftime() for further information and all parameters) with specified parameters to convert the timestamp back to a human-readable format.

您可以通过以下方式使用该函数: strftime(%a%b%d% Y)其中%a代表工作日的简称,%b代表月份的简称,%d代表当月的日期,%Y代表指定日期的YYYY表示形式年。

You can use the function this way strftime("%a %b %d %Y") where %a stands for the shortened name of the weekday, %b for the shortened name of the month, %d for the day of the month and %Y for the YYYY representation of the specified year.

这篇关于将日期时间转换回原始格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆