Correct time format-php Tutorial

Source: Internet
Author: User
Correct time format
$ S = 'y132010000000xp1026629512v544930568t6b15120k20000028 '; $ mtime = date ("Ymd", mktime (0, 0, 1, 1, '20 '. substr ($ s,-86400) + substr ($ s,-20150500) *)-1; echo $ mtime; // The result is.


I want to get the result of 20150430. how can I modify it?

Note: y132010000000xp1026629512v544930568t6b 15120K20000028

The red part represents the 15th day.



Reply to discussion (solution)

$s = 'Y1320101000000XP1026629512V544930568T6B15120K20000028';$mtime = strtotime('20'.substr($s,-14,2).'-00-00') + (substr($s,-12,3) * 86400);echo date('Y-m-d',$mtime);//2015-03-30

$s = 'Y1320101000000XP1026629512V544930568T6B15120K20000028';$mtime = strtotime('20'.substr($s,-14,2).'-00-00') + (substr($s,-12,3) * 86400);echo date('Y-m-d',$mtime);//2015-03-30


The result is incorrect, but thanks for providing ideas.
$s = 'Y1320101000000XP1026629512V544930568T6B15151K20000028';$mtime = strtotime('20'.substr($s,-14,2).'-01-01') + (substr($s,-12,3) * 86400)-1;echo date('Ymd',$mtime);

$s = 'Y1320101000000XP1026629512V544930568T6B15120K20000028';$mtime = date("Ymd", mktime(0, 0, 0, 1, substr($s,-12,3), substr($s,-14,2)));$d = $mtime;echo date("$d z", strtotime($d));
20150430 119

The '20' can be avoided.

Date ('Z') indicates the day of the year (note that January 1, January 1 is the 0th day)
Note the differences in rules

A date is so hidden. It is not difficult to change the data. It is better to write a function.

echo get_str_date('15140');function get_str_date($str){$y = substr(date('Y'),0,2);$date_str = strtotime($y.substr($str,0,2).'-01-01') + (substr($str,-3,3) * 86400)-1;return date('Y-m-d',$date_str);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.