转换日期格式yyyy-mm-dd => dd-mm-yyyy [英] Convert date format yyyy-mm-dd => dd-mm-yyyy
本文介绍了转换日期格式yyyy-mm-dd => dd-mm-yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将日期从yyyy-mm-dd转换为dd-mm-yyyy(但不是在SQL中);但是我不知道日期功能如何需要时间戳,我无法从此字符串中获取时间戳。
I am trying to convert a date from yyyy-mm-dd to dd-mm-yyyy (but not in SQL); however I don't know how the date function requires a timestamp, and I can't get a timestamp from this string.
这是怎么可能的?
推荐答案
使用 strtotime()
和 date() code>:
Use strtotime()
and date()
:
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
(请参阅 strtotime 和 date 文档在PHP网站上)。
(see strtotime and date docs on the PHP site).
修改:请注意,这是对原始问题的快速解决方案。对于更广泛的转化,您应该真正使用 DateTime
类来解析&格式: - )
Edit: 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 & format :-)
这篇关于转换日期格式yyyy-mm-dd => dd-mm-yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文