简体   繁体   English

如何获取给定年份的哪个月份在php中?

[英]how can i get which month a given year day is in in php?

I have been given year day (1-366) and I need to figure out which month it is in, how can I do this? 我被定为年份(1-366),我需要弄清楚它所在的月份,该怎么办? Well, I actually have a date string like : year, day or year, minute of day, second and I ultimately want to create a POSIX timestamp from it, how can I do this? 好吧,我实际上有一个日期字符串,例如:year,day或year,day of minutes,second,我最终想从中创建一个POSIX时间戳,我该怎么做?

Thank you! 谢谢!

If you have PHP >= 5.3, then you can use DateTime::createFromFormat . 如果您的PHP> = 5.3,则可以使用DateTime::createFromFormat

$day = 176;
$date = DateTime::createFromFormat('z', $day);
echo $date->getTimestamp();  // 1372275280
<?php
$year=2013;
$d=360;
echo date("m",strtotime("1/1/$year + $d days")) 
?>

Use the date function to get a posix time stamp. 使用日期功能获取posix时间戳。

To get the month of a certain date, use intval(date('m'), mktime($h,$m,$s,$month,$day,$year)) 要获取某个日期的月份,请使用intval(date('m'),mktime($ h,$ m,$ s,$ month,$ day,$ year))

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

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