Home >Backend Development >PHP Tutorial >诸如这样的格式:六月, 25th 2014 怎么转成时间戳?

诸如这样的格式:六月, 25th 2014 怎么转成时间戳?

WBOY
WBOYOriginal
2016-06-06 20:44:531012browse

诸如这样的格式:「六月, 25th 2014」怎么转成时间戳?

回复内容:

诸如这样的格式:「六月, 25th 2014」怎么转成时间戳?

如果是 js,你需要 moment。

比如你这个需求,这样写就好了。

<code class="lang-js">var m = moment("六月, 25th 2014", "MMM, DD YYYY", "zh-cn");
console.log("date:", m.format("YYYY-MM-DD")); // writes "2014-05-25"
</code>

如果只是月份是中文的话可以做一个替换,比如六月替换成June。如果是比较杂的话就不用客气直接用有道词典的API翻译成英文吧,然后直接用strtotime()就好了!

<code>$text = "六月, 25th 2014";
$text = str_replace('六月', 'June', $text);
echo strtotime($text);
//1403625600
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn