Php如何从一年的日子到今天,反之亦然

一年中的第n天如何进入PHP,如下所示:
getdatefromday(275,2012)

输出一个日期(如果一个对象更好).

而我也想做相反的事情,像getdayoftheyear(“2012年8月21日”)

这是很容易的.您应该读取DateTime对象的createFromFormat静态方法 here,日期函数 here和strtotime函数 here.
// This should get you a DateTime object from the date and year.
function getDateFromDay($dayOfYear,$year) {
  $date = DateTime::createFromFormat('z Y',strval($dayOfYear) . ' ' . strval($year));
  return $date;
}

// This should get you the day of the year and the year in a string.
date('z Y',strtotime('21 oct 2012'));

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...