Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

php - 在PHP中转换日期格式(Convert a date format in PHP)

I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in SQL);

(我正在尝试将日期从yyyy-mm-dddd-mm-yyyy (但在SQL中不是);)

however I don't know how the date function requires a timestamp, and I can't get a timestamp from this string.

(但是我不知道date函数如何需要时间戳,并且我无法从该字符串获取时间戳。)

How is this possible?

(这怎么可能?)

  ask by matthy translate from so

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

1 Reply

0 votes
by (71.8m points)

Use strtotime() and date() :

(使用strtotime()date() :)

$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));

(See the strtotime and date documentation on the PHP site.)

((请参阅PHP网站上的strtotimedate文档。))

Note that this was a quick solution to the original question.

(请注意,这是对原始问题的快速解决方案。)

For more extensive conversions, you should really be using the DateTime class to parse and format :-)

(为了进行更广泛的转换,您实际上应该使用DateTime类来解析和格式化:-))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...