作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 php 中从一年中的第 n 天到这样的日期:
getdatefromday(275, 2012)
它输出一个日期(如果是一个对象更好)。
我也想做相反的事情,比如getdayoftheyear("21 oct 2012")
最佳答案
这一切都很简单。您应该阅读 DateTime
对象的 createFromFormat
静态方法 here ,日期
函数here和 strtotime
函数 here .
// This should get you a DateTime object from the date and year.
function getDateFromDay($year, $dayOfYear) {
$date = DateTime::createFromFormat('z Y', strval($year) . ' ' . strval($dayOfYear));
return $date;
}
// This should get you the day of the year and the year in a string.
date('z Y', strtotime('21 oct 2012'));
关于Php如何从一年中的某一天转到日期,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9735528/
我是一名优秀的程序员,十分优秀!