简体   繁体   English

将yymmddhhmm日期/时间字符串转换为PHP时间戳

[英]Convert yymmddhhmm date/time string to PHP timestamp

I have a string that is a 10 digit date/time representation in the format of yymmddhhmm, eg: 我有一个以yymmddhhmm格式表示的10位日期/时间表示形式的字符串,例如:

1304282240 1304282240

is the 28th of April, 2013 22:40 (28/04/13 in the DD/MM/YY format) 是2013年4月28日22:40(DD / MM / YY格式的2013年4月28日)

I need to convert this into a valid PHP timestamp but I'm getting stuck using the Date and strtotime functions, and not sure if that is the best approach in any case. 我需要将其转换为有效的PHP时间戳,但是我使用Date和strtotime函数陷入困境,并且不确定在任何情况下这是否是最佳方法。

Update: I've added these lines to my code: 更新:我已经在代码中添加了以下几行:

$date = DateTime::createFromFormat('ymdHi', '1304282240');
echo $date->format('m/d/Y h:i:s A');

appears to work 似乎起作用

我相信您想要这样的东西:

$date = DateTime::createFromFormat('ymdHi', '1304282240');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM