背景我有一个设置为特定(英国)时间的事件列表。我想让用户看到他们本地时间的事件时间。例如:如果事件在英国时间20:30开始,荷兰用户应该看到开始时间为21:30。问题我已经设置好所有内容,并且正在创建新的DateTime对象来设置我的事件。但是,当我指定我的DateTimeZone对象时,它显示+00:00而不是我为其创建的DateTimeZone。这意味着新时间不正确。因此,设置为20:30英国时间的时间仍会显示为20:30NL时间,而不是21:30。代码这是我写的代码。据我所知,我所做的一切都是正确的,但是DateTimeZone在分配给DateTime对象时仍然不正确。默认设置:
DateTimeZone类中有奇怪的常量classDateTimeZone{constUTC=1024;constALL=2047;...}我试图找到关于它们的任何信息。也尝试过使用它们:$dtz=newDateTimeZone(DateTimeZone::UTC);//throwsExceptionwithmessage//DateTimeZone::__construct():Unknownorbadtimezone(1024)或$dt=newDatetime('2016-02-0110:00:00',DateTimeZone::UTC);//throwsExceptionwith
我有一个在东部时区的时间,但我想将它调整为中部时区。两个时区都在美国。我从来没有这样做过?我不知道如何转换它。请帮帮我好吗? 最佳答案 这是一种可能的方法:$dt=newDateTime('2011-02-2216:15:20',newDateTimeZone('America/New_York'));echo$dt->format('r').PHP_EOL;$dt->setTimezone(newDateTimeZone('America/Chicago'));echo$dt->format('r').PHP_EOL;您可以获得可
我想将一个DateTimeZone对象传递给我的类Test中的方法。我有以下代码:classTest{function__construct($timezone_object=newDateTimeZone()){//Dosomethingwiththeobjectpassedinmyfunctionhere}}不幸的是,上面的方法不起作用。它给了我一个错误。我知道我可以改为执行以下操作:classTest{function__construct($timezone_object=NULL){if($timezone_object==NULL)$to_be_processed=newD
这个问题在这里已经有了答案:ProblemswithPHPnamespacesandbuilt-inclasses,howtofix?(3个答案)关闭7年前。我尝试在PHPv5.3.13上运行以下代码,但仍然出现找不到类的错误:$tZone=newDateTimeZone("Europe/Amsterdam");如何在5.3.13上使用DateTimeZone?
当使用PHPDateTime类并尝试设置DateTimeZone时,我会根据设置方式得到不同的结果:使用DateTime::__construct或使用DateTime::setTimezone方法。这是一个例子:$date='2014-08-01'$dateTimeOne=newDateTime($date,newDateTimeZone('America/Los_Angeles'));echo$dateTimeOne->format('Y-m-d\TH:i:sP');//2014-08-01T00:00:00-07:00$dateTimeTwo=newDateTime($date)
我一直在尝试使用以下代码将服务器的日期和时间转换为用户的日期和时间@TestpublicvoidplayingWithJodaTime(){LocalDateTimelocalDateTime=newLocalDateTime();System.out.println("serverlocalDateTime:"+localDateTime.toDateTime(DateTimeZone.getDefault()).toDate());System.out.println("user'slocalDateTime:"+localDateTime.toDateTime(DateTimeZ
一直在研究Joda时区,发现以下内容看起来很奇怪。我运行了以下代码DateTimeZonegmt=DateTimeZone.forID("Etc/GMT");DateTimeZonegmtPlusOne=DateTimeZone.forID("Etc/GMT+1");DateTimeZonegmtMinusOne=DateTimeZone.forID("Etc/GMT-1");System.out.println(newDateTime(gmt).toString());System.out.println(newDateTime(gmtPlusOne).toString());Sys
JodaTime的LocalDate将自己描述为:LocalDateisanimmutabledatetimeclassrepresentingadatewithoutatimezone.但是有一个LocalDate(Objectinstant,DateTimeZonezone)接受时区的构造函数。如果对象是无时区的,那么时区构造函数的目的是什么?构造函数JavaDocs指出:ConstructsaninstancefromanObjectthatrepresentsadatetime,forcingthetimezonetothatspecified.我不知道“强制指定时区”是什么意
我正在尝试使用JodaTime将本地日期转换为UTC.我使用的代码如下所示,效果很好。DatelocalDate=newDate();System.out.println("LocalDate:"+localDate);DateTimeZonetz=DateTimeZone.getDefault();DateutcDate=newDate(tz.convertLocalToUTC(localDate.getTime(),false));System.out.println("UTCDate:"+utcDate);Output:LocalDate:WedMay2911:54:46EEST