本文整理汇总了PHP中DateTime::setTime方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::setTime方法的具体用法?PHP DateTime::setTime怎么用?PHP DateTime::setTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime
的用法示例。
在下文中一共展示了DateTime::setTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hour_module
function hour_module($module)
{
global $DB, $USER;
//in format HH:MM:SS (varchar)
//Define lthe hours for misreservas.php
$modules = $DB->get_record('bookingrooms_modules', array("id" => $module));
$start = explode(":", $modules->hour_start);
$end = explode(":", $modules->hour_end);
$a = $start[0];
$b = $start[1];
$c = 00;
//hour;minute;second
$d = $end[0];
$e = (int) $end[1];
$f = 00;
//hour;minute;second
$minutes = str_replace(' ', '', $e);
$ModuleStart = new DateTime();
// Is left hour and minutes in 0 (midnigth)
$ModuleStart->setTime($a, $b, 0);
$ModuleEnd = new DateTime();
// Is left hour and minutes in 0 (midnigth)
$ModuleEnd->setTime($d, $e, 0);
$hour = array($ModuleStart, $ModuloEnd);
//var_dump($hour);
return $hour;
//returns $hour[start] y $hour[end]
}
示例2: __construct
/**
* @param string $date String representation of date.
* @param string $format PHP date format. If not specified, the format is got from the current culture.
*
* @throws Main\ObjectException
*/
public function __construct($date = null, $format = null)
{
$this->value = new \DateTime();
if ($date !== null && $date !== "")
{
if ($format === null)
{
$format = static::getFormat();
}
$parsedValue = date_parse_from_format($format, $date);
//Ignore errors when format is longer than date
//or date string is longer than format
if ($parsedValue['error_count'] > 1)
{
if (
current($parsedValue['errors']) !== 'Trailing data'
&& current($parsedValue['errors']) !== 'Data missing'
)
{
throw new Main\ObjectException("Incorrect date: ".$date);
}
}
$this->value->setDate($parsedValue['year'], $parsedValue['month'], $parsedValue['day']);
}
$this->value->setTime(0, 0, 0);
}
示例3: boolgetafwezigheidleerlingiddate
public function boolgetafwezigheidleerlingiddate($datum, $leerlingid)
{
$date = new DateTime($datum);
//$date->format('Y-m-d H');
// print_r($date);
$date->setTime(0, 0, 0);
$datumstart = $date->format('Y-m-d H');
$date->setTime(23, 0, 0);
$datumend = $date->format('Y-m-d H');
// echo "<br/>";
// print_r($datumstart);
// echo "<br/>";
// print_r($datumend);
// echo "<br/>";
$result = false;
$sql = "select * from afwezigheden where leerlingid = '" . $leerlingid . "' AND datum < '" . $datumend . "' AND datum > '" . $datumstart . "' ";
$dbh = new PDO(DBConfig::$DB_CONNSTRING, DBConfig::$DB_USERNAME, DBConfig::$DB_PASSWORD);
$resultSet = $dbh->query($sql);
foreach ($resultSet as $rij) {
if ($rij["afwezigheidid"] > 0) {
$result = true;
//to see if there was found a match
}
}
$dbh = null;
return $result;
}
示例4: increment
public function increment(\DateTime $date, $invert = false, $parts = null)
{
if (is_null($parts)) {
if ($invert) {
$date->modify('-1 minute');
} else {
$date->modify('+1 minute');
}
return $this;
}
$parts = strpos($parts, ',') !== false ? explode(',', $parts) : array($parts);
$minutes = array();
foreach ($parts as $part) {
$minutes = array_merge($minutes, $this->getRangeForExpression($part, 59));
}
$current_minute = $date->format('i');
$position = $invert ? count($minutes) - 1 : 0;
if (count($minutes) > 1) {
for ($i = 0; $i < count($minutes) - 1; $i++) {
if (!$invert && $current_minute >= $minutes[$i] && $current_minute < $minutes[$i + 1] || $invert && $current_minute > $minutes[$i] && $current_minute <= $minutes[$i + 1]) {
$position = $invert ? $i : $i + 1;
break;
}
}
}
if (!$invert && $current_minute >= $minutes[$position] || $invert && $current_minute <= $minutes[$position]) {
$date->modify(($invert ? '-' : '+') . '1 hour');
$date->setTime($date->format('H'), $invert ? 59 : 0);
} else {
$date->setTime($date->format('H'), $minutes[$position]);
}
return $this;
}
示例5: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$datetime = new DateTime('today');
DB::table('events')->insert(['name' => 'Pisyek', 'title' => 'SI Finance', 'start_time' => strtotime($datetime->setTime(10, 00)->format('Y-m-d H:i:s')), 'end_time' => strtotime($datetime->add(new DateInterval('PT1H'))->format('Y-m-d H:i:s'))]);
$datetime = new DateTime('tomorrow');
DB::table('events')->insert(['name' => 'Aron Kumar', 'title' => 'Meeting HR & You', 'start_time' => strtotime($datetime->format('Y-m-d H:i:s')), 'end_time' => strtotime($datetime->add(new DateInterval('PT2H'))->format('Y-m-d H:i:s'))]);
$datetime = new DateTime('yesterday');
DB::table('events')->insert(['name' => 'Jericho', 'title' => 'HYPE', 'start_time' => strtotime($datetime->setTime(11, 00)->format('Y-m-d H:i:s')), 'end_time' => strtotime($datetime->add(new DateInterval('PT1H'))->format('Y-m-d H:i:s'))]);
DB::table('events')->insert(['name' => 'Remy', 'title' => 'HC PDC', 'start_time' => strtotime($datetime->setTime(14, 00)->format('Y-m-d H:i:s')), 'end_time' => strtotime($datetime->add(new DateInterval('PT2H'))->format('Y-m-d H:i:s'))]);
}
示例6: increment
public function increment(\DateTime $date, $invert = false)
{
if ($invert) {
$date->modify('previous day');
$date->setTime(23, 59);
} else {
$date->modify('next day');
$date->setTime(0, 0);
}
return $this;
}
示例7: increment
/**
* {@inheritdoc}
*/
public function increment(DateTime $date, $invert = false)
{
if ($invert) {
$date->modify('last day of previous month');
$date->setTime(23, 59);
} else {
$date->modify('first day of next month');
$date->setTime(0, 0);
}
return $this;
}
示例8: increment
public function increment(\DateTime $date, $invert = false)
{
if (${${"GLOBALS"}["ttbetj"]}) {
$date->modify("previous day");
$date->setTime(23, 59);
} else {
$date->modify("next day");
$date->setTime(0, 0);
}
return $this;
}
示例9: increment
public function increment(\DateTime $date, $invert = false)
{
if (${${"GLOBALS"}["icdiaipis"]}) {
$date->modify("-1 year");
$date->setDate($date->format("Y"), 12, 31);
$date->setTime(23, 59, 0);
} else {
$date->modify("+1 year");
$date->setDate($date->format("Y"), 1, 1);
$date->setTime(0, 0, 0);
}
return $this;
}
示例10: fetchNewUser
/**
* @param \PDO $pdo
* @param string $date
*
* @return array [uid, uid]
*/
protected function fetchNewUser(\PDO $pdo, $date)
{
$dateTime = new \DateTime($date);
$dateTime->setTime(0, 0, 0);
$fromTs = $dateTime->getTimestamp();
$dateTime->setTime(23, 59, 59);
$toTs = $dateTime->getTimestamp();
$sql = 'SELECT uid FROM tbl_user WHERE logintime>=? AND logintime<=?';
$statement = $pdo->prepare($sql);
$statement->execute([$fromTs, $toTs]);
$uidList = $statement->fetchAll(\PDO::FETCH_COLUMN);
return $uidList;
}
示例11: increment
public function increment(\DateTime $date, $invert = false)
{
if ($invert) {
$date->modify('-1 year');
$date->setDate($date->format('Y'), 12, 31);
$date->setTime(23, 59, 0);
} else {
$date->modify('+1 year');
$date->setDate($date->format('Y'), 1, 1);
$date->setTime(0, 0, 0);
}
return $this;
}
示例12: generateIdentification
public function generateIdentification(InvoiceEntity $invoiceEntity)
{
$date = new \DateTime();
$account = $invoiceEntity->getSupplier();
$format = $account->getIdentificationFormat();
$dateFrom = new \DateTime();
if ($account->getIdentificationInterval() === AccountEntity::INTERVAL_YEAR) {
$dateFrom->setTime(0, 0, 0);
$dateFrom->setDate($dateFrom->format('Y'), 1, 1);
$dateTo = \DateTime::createFromFormat('Y-m-d', intval($dateFrom->format('Y')) + 1 . '-01-01');
$dateTo->setTime(0, 0, 0);
} elseif ($account->getIdentificationInterval() === AccountEntity::INTERVAL_MONTH) {
$dateFrom->setTime(0, 0, 0);
$dateFrom->setDate($dateFrom->format('Y'), $dateFrom->format('m'), 1);
$year = intval($dateFrom->format('Y'));
$month = intval($dateFrom->format('m')) + 1;
if ($month > 12) {
$month = $month - 12;
$year++;
}
$dateTo = \DateTime::createFromFormat('Y-m-d', $year . '-' . $month . '-01');
$dateTo->setTime(0, 0, 0);
} elseif ($account->getIdentificationInterval() === AccountEntity::INTERVAL_QUARTER) {
$month = intval($dateFrom->format('m'));
$year = intval($dateFrom->format('Y'));
$dateFrom->setTime(0, 0, 0);
$dateFrom->setDate($year, $month % 4 * 4, 0);
$month = $month + 4;
if ($month > 12) {
$month = $month - 12;
$year++;
}
$dateTo = \DateTime::createFromFormat('Y-m-d', $year . '-' . $month % 4 * 4 . '-01');
$dateTo->setTime(0, 0, 0);
}
$qb = $this->invoiceRepository->createQueryBuilder('a')->select('COUNT(a.id)')->andWhere('a.identification IS NOT NULL')->andWhere('a.supplier = :supplier')->setParameter('supplier', $account->id);
if (isset($dateTo)) {
$qb = $qb->andWhere('a.date >= :dateFrom')->setParameter('dateFrom', $dateFrom)->andWhere('a.date < :dateTo')->setParameter('dateTo', $dateTo);
}
$identification = intval($qb->getQuery()->getSingleScalarResult()) + 1;
if (preg_match_all('/\\?(\\d+)/is', $format, $matches)) {
$number = $matches[1][0];
$format = str_replace('?' . $number, sprintf('%0' . $number . 'd', $identification), $format);
}
$exDate = clone $date;
$exDate->modify('+' . $account->getDue() . ' days');
$invoiceEntity->setDate($date);
$invoiceEntity->setExpirationDate($exDate);
$invoiceEntity->setIdentification($date->format($format));
$this->invoiceRepository->save($invoiceEntity);
}
示例13: getDatesArrayForStationReports
public static function getDatesArrayForStationReports($quickReportType, $fromDateStr, $toDateStr)
{
$dateArr = null;
$fromDate = new DateTime($toDateStr);
$toDate = new DateTime($toDateStr);
if ($quickReportType != "null") {
$fromDate = new DateTime();
$toDate = new DateTime();
}
//$fromDate->setTimezone($timezone);
//$toDate ->setTimezone($timezone);
$fromDate->setTime(0, 0, 0);
if ($quickReportType == "today") {
//$toDate = $toDate->setTime(23,59,59);
} else {
if ($quickReportType == "last7days") {
$fromDate->add(DateInterval::createFromDateString('-7 days'));
$fromDate->setTime(0, 0, 0);
} else {
if ($quickReportType == "last30days") {
$fromDate->add(DateInterval::createFromDateString('-1 month'));
$fromDate = $fromDate->setTime(0, 0, 0);
} else {
if ($quickReportType == "last6months") {
$fromDate->add(DateInterval::createFromDateString('-6 months'));
$fromDate = $fromDate->setTime(0, 0, 0);
} else {
if ($quickReportType == "thisyear") {
$d = $fromDate->format('d');
$m = $fromDate->format('m');
$Y = $fromDate->format('Y');
$fromDate = $fromDate->setDate($Y, 1, 1);
// set the wanted day for the month
$fromDate = $fromDate->setTime(0, 0, 0);
} else {
if ($quickReportType == "null") {
$fromDate = new DateTime($fromDateStr);
$toDate = new DateTime($toDateStr);
}
}
}
}
}
}
$fromDateAStr = $fromDate->format("Y/m/d H:i:s");
$toDateAStr = $toDate->format("Y/m/d H:i:s");
$dateArr = array('fromDate' => $fromDateAStr, 'toDate' => $toDateAStr);
return $dateArr;
}
示例14: increment
/**
* {@inheritdoc}
*/
public function increment(DateTime $date, $invert = false)
{
if ($invert) {
// $date->modify('last day of previous month'); // remove for php 5.2 compat
$date->modify('previous month');
$date->modify($date->format('Y-m-t'));
$date->setTime(23, 59);
} else {
//$date->modify('first day of next month'); // remove for php 5.2 compat
$date->modify('next month');
$date->modify($date->format('Y-m-01'));
$date->setTime(0, 0);
}
return $this;
}
示例15: __construct
/**
* @param string $date String representation of date
* @param string $format PHP date format. If not specified, the format is got from the current culture.
* @throws Main\ObjectException
*/
public function __construct($date = null, $format = null)
{
if ($date === null || $date === "") {
$this->value = new \DateTime();
} else {
if ($format === null) {
$format = static::getFormat();
}
$this->value = \DateTime::createFromFormat($format, $date);
if (empty($this->value)) {
throw new Main\ObjectException("Incorrect date: " . $date);
}
}
$this->value->setTime(0, 0, 0);
}