Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

php - 使用PHP从MySQL日期时间转换为另一种格式(Convert from MySQL datetime to another format with PHP)

I have a datetime column in MySQL.

(我在MySQL中有一个datetime列。)

How can I convert it to the display as mm/dd/yy H:M (AM/PM) using PHP?

(如何使用PHP将其转换为mm / dd / yy H:M(AM / PM)显示 ?)

  ask by Tim Boland translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you're looking for a way to normalize a date into MySQL format, use the following

(如果您正在寻找一种将日期标准化为MySQL格式的方法,请使用以下命令)

$phpdate = strtotime( $mysqldate );
$mysqldate = date( 'Y-m-d H:i:s', $phpdate );

The line $phpdate = strtotime( $mysqldate ) accepts a string and performs a series of heuristics to turn that string into a unix timestamp.

($phpdate = strtotime( $mysqldate )接受一个字符串并执行一系列试探法,以将该字符串转换为unix时间戳。)

The line $mysqldate = date( 'Ymd H:i:s', $phpdate ) uses that timestamp and PHP's date function to turn that timestamp back into MySQL's standard date format.

($mysqldate = date( 'Ymd H:i:s', $phpdate )使用该时间戳和PHP的date函数将该时间戳转换回MySQL的标准日期格式。)

( Editor Note : This answer is here because of an original question with confusing wording, and the general Google usefulness this answer provided even if it didnt' directly answer the question that now exists)

(( 编者注 :之所以在这里给出此答案,是因为最初的问题带有令人困惑的措辞,而且即使该答案没有直接回答现在存在的问题,该答案也具有一般的Google实用性))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...