如何从周数获得日期日数和年份 [英] How to get date from week number & day number and year?

查看:162
本文介绍了如何从周数获得日期日数和年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从周号,日数和年份获取日期。



例如:

 周数= 52 
日数= 4(第52周)
年= 2013
pre>

在这种情况下,日期应为 26-12-2013



如何使用PHP?我已经尝试使用 strtotime(),但我对这些格式感到困惑。有人可以帮忙吗?

解决方案

使用 setISODate()

 <?php 
$ gendate = new DateTime();
$ gendate-> setISODate(2013,52,4); //年,周num,day
echo $ gendate->格式('d-m-Y'); //prints26-12-2013


I'm trying to get the date from the week number, day number and year.

For eg:

week number = 52   
day number = 4 (of week 52)  
year = 2013  

In this case, the date should be 26-12-2013.

How can I do it using PHP? I've already tried with strtotime(), but I'm confused about the formats. Can someone help?

解决方案

Make use of setISODate()

<?php
$gendate = new DateTime();
$gendate->setISODate(2013,52,4); //year , week num , day
echo $gendate->format('d-m-Y'); //"prints"  26-12-2013

这篇关于如何从周数获得日期日数和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆