当前位置: 首页>>代码示例>>PHP>>正文


PHP Time::withHourMinuteSecond方法代码示例

本文整理汇总了PHP中Time::withHourMinuteSecond方法的典型用法代码示例。如果您正苦于以下问题:PHP Time::withHourMinuteSecond方法的具体用法?PHP Time::withHourMinuteSecond怎么用?PHP Time::withHourMinuteSecond使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Time的用法示例。


在下文中一共展示了Time::withHourMinuteSecond方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_converting

 /**
  * Test converting
  */
 function test_converting()
 {
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5));
     // asDate()
     $temp = $dateAndTime->asDate();
     $this->assertTrue($temp->isEqualTo(Date::withYearMonthDay(2005, 6, 4)));
     // asDuration()
     $temp = $dateAndTime->asDuration();
     $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510)));
     // asDateAndTime()
     $temp = $dateAndTime->asDateAndTime();
     $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5))));
     // asLocal()
     $startDuration = Duration::withHours(-5);
     $localOffset = DateAndTime::localOffset();
     $difference = $localOffset->minus($startDuration);
     $temp = $dateAndTime->asLocal();
     $local = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15 + $difference->hours(), 25, 10, $localOffset);
     $this->assertTrue($temp->isEqualTo($local));
     // asMonth()
     $temp = $dateAndTime->asMonth();
     $this->assertTrue($temp->isEqualTo(Month::withMonthYear(6, 2005)));
     // asSeconds()
     $localOffset = DateAndTime::localOffset();
     $this->assertEqual($dateAndTime->asSeconds(), 3295369510 + $localOffset->asSeconds());
     // asTime()
     $temp = $dateAndTime->asTime();
     $this->assertTrue($temp->isEqualTo(Time::withHourMinuteSecond(15, 25, 10)));
     $this->assertTrue($temp->isEqualTo(Time::withSeconds(55510)));
     // asTimeStamp()
     $temp = $dateAndTime->asTimeStamp();
     $this->assertTrue($temp->isEqualTo(TimeStamp::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5))));
     // asUTC()
     $temp = $dateAndTime->asUTC();
     $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 20, 25, 10, Duration::withHours(0))));
     // asWeek()
     $temp = $dateAndTime->asWeek();
     $this->assertTrue($temp->isEqualTo(Week::starting($dateAndTime)));
     // asYear()
     $temp = $dateAndTime->asYear();
     $this->assertTrue($temp->isEqualTo(Year::starting($dateAndTime)));
     // midnight();
     $temp = $dateAndTime->atMidnight();
     $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 6, 4, 0, 0, 0)));
     // middleOf()
     $dat = DateAndTime::withYearDay(2005, 100);
     $timespan = $dat->middleOf(Duration::withDays(100));
     $start = $timespan->start();
     $duration = $timespan->duration();
     $end = $timespan->end();
     $this->assertEqual($start->dayOfYear(), 50);
     $this->assertTrue($start->isEqualTo(DateAndTime::withYearDay(2005, 50)));
     $this->assertEqual($duration->days(), 100);
     $this->assertEqual($end->dayOfYear(), 149);
     // to()
     $datA = DateAndTime::withYearDay(2005, 125);
     $datB = DateAndTime::withYearDay(2006, 125);
     $timespan = $datA->to($datB);
     $this->assertEqual($timespan->startYear(), 2005);
     $this->assertEqual($timespan->dayOfYear(), 125);
     $duration = $timespan->duration();
     $this->assertTrue($duration->isEqualTo(Duration::withDays(365)));
     $end = $timespan->end();
     $this->assertEqual($end->julianDayNumber(), 2453860);
     $this->assertEqual($end->julianDayNumber() - $datA->julianDayNumber(), 364);
     $this->assertEqual($end->year(), 2006);
     $this->assertEqual($end->dayOfYear(), 124);
     $this->assertTrue($end->isEqualTo(DateAndTime::withYearDayHourMinuteSecond(2006, 124, 23, 59, 59)));
     // withOffset()
     $temp = $dateAndTime->withOffset(Duration::withHours(-7));
     $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-7))));
 }
开发者ID:adamfranco,项目名称:harmoni,代码行数:75,代码来源:DateAndTimeTestCase.class.php

示例2: test_converting

 /**
  * Test converting methods
  * 
  */
 function test_converting()
 {
     $time = Time::withHourMinuteSecond(15, 25, 10);
     // asDate ()
     $temp = $time->asDate();
     $this->assertTrue($temp->isEqualTo(Date::today()));
     $this->assertEqual(strtolower(get_class($temp)), 'date');
     // asDateAndTime ()
     $temp = $time->asDateAndTime();
     $comparison = DateAndTime::midnight();
     $comparison = $comparison->plus(Duration::withSeconds(55510));
     $this->assertTrue($temp->isEqualTo($comparison));
     $this->assertEqual(strtolower(get_class($temp)), 'dateandtime');
     // asDuration ()
     $temp = $time->asDuration();
     $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510)));
     $this->assertEqual(strtolower(get_class($temp)), 'duration');
     // asMonth ()
     $temp = $time->asMonth();
     $this->assertTrue($temp->isEqualTo(Month::starting(Date::today())));
     $this->assertEqual(strtolower(get_class($temp)), 'month');
     // asSeconds ()
     $this->assertEqual($time->asSeconds(), 55510);
     // asTime ()
     $temp = $time->asTime();
     $this->assertTrue($temp->isEqualTo($time));
     $this->assertEqual(strtolower(get_class($temp)), 'time');
     // asTimeStamp ()
     $temp = $time->asTimeStamp();
     $comparison = TimeStamp::midnight();
     $comparison = $comparison->plus(Duration::withSeconds(55510));
     $this->assertTrue($temp->isEqualTo($comparison));
     $this->assertEqual(strtolower(get_class($temp)), 'timestamp');
     // asWeek ()
     $temp = $time->asWeek();
     $this->assertTrue($temp->isEqualTo(Week::starting(Date::today())));
     $this->assertEqual(strtolower(get_class($temp)), 'week');
     // asYear ()
     $temp = $time->asYear();
     $this->assertTrue($temp->isEqualTo(Year::starting(Date::today())));
     $this->assertEqual(strtolower(get_class($temp)), 'year');
     // to ()
     $today = DateAndTime::today();
     $tomorrow = DateAndTime::tomorrow();
     $result = $time->to($tomorrow);
     $this->assertEqual(strtolower(get_class($result)), 'timespan');
     $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 34, 50))));
     $result = $time->to(Time::withHourMinuteSecond(23, 25, 10));
     $this->assertEqual(strtolower(get_class($result)), 'timespan');
     $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 0, 0))));
 }
开发者ID:adamfranco,项目名称:harmoni,代码行数:55,代码来源:TimeTestCase.class.php


注:本文中的Time::withHourMinuteSecond方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。