本文整理汇总了PHP中Datetime::setDate方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::setDate方法的具体用法?PHP Datetime::setDate怎么用?PHP Datetime::setDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datetime
的用法示例。
在下文中一共展示了Datetime::setDate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toDateTime
public function toDateTime()
{
$dateTime = new \Datetime();
$dateTime->setDate($this->year, $this->month, $this->day);
$dateTime->setTime(0, 0, 0);
return $dateTime;
}
示例2: findAllPerMonth
/**
* @return array
*/
public function findAllPerMonth()
{
$sql = 'SELECT DISTINCT CONCAT(MONTH(`created`), \' \', YEAR(`created`)) as month, avg(`usage`) as average, username FROM oc_uc_storageusage WHERE `usage` > 0 GROUP BY username, month';
$query = $this->db->prepareQuery($sql);
$result = $query->execute();
$entities = array();
while ($row = $result->fetch()) {
if (!isset($entities[$row['username']])) {
$entities[$row['username']] = array();
}
$date = explode(' ', $row['month']);
$dateTime = new \Datetime();
$dateTime->setDate($date[1], $date[0], 1);
$entities[$row['username']] = array_merge($entities[$row['username']], array(new StorageUsage($dateTime, $row['average'], $row['username'])));
}
return $entities;
}
示例3: parsePerMonthEntities
/**
* Parse the results from the per month entities found
*
* @param \OC_DB_StatementWrapper $result
* @return array
*/
private function parsePerMonthEntities($result)
{
$entities = array();
while ($row = $result->fetch()) {
if (!isset($entities[$row['username']])) {
$entities[$row['username']] = array();
}
$date = explode(' ', $row['month']);
$dateTime = new \Datetime();
$dateTime->setDate($date[1], $date[0], 1);
$entities[$row['username']] = array_merge($entities[$row['username']], array(new StorageUsage($dateTime, $row['average'], $row['username'], $row['maximumusage'])));
}
return $entities;
}
示例4: updateAction
public function updateAction($id, Request $request)
{
$session = $request->getSession();
if (!$session->get('AdminAuth')) {
return $this->redirect($this->generateUrl("login"));
}
$ArticleRepository = $this->getDoctrine()->getManager()->getRepository('EntityBundle:Article');
$articleOLD = $ArticleRepository->find($id);
$arraydatedebut = array('day' => $articleOLD->getDateDebut()->format('d'), 'month' => $articleOLD->getDateDebut()->format('m'), 'year' => $articleOLD->getDateDebut()->format('Y'));
// var_dump($arraydatedebut);
$arraydatefin = array('day' => $articleOLD->getDateFin()->format('d'), 'month' => $articleOLD->getDateDebut()->format('m'), 'year' => $articleOLD->getDateDebut()->format('Y'));
// var_dump($arraydatefin);
$em = $this->getDoctrine()->getManager();
$build['article'] = $articleOLD;
$build['datedebut'] = $arraydatedebut;
$build['datefin'] = $arraydatefin;
$build['years'] = range(1331, 1407);
$localisation = $articleOLD->getLocalisation($articleOLD);
$image = $articleOLD->getImage($articleOLD);
if (!$articleOLD) {
throw $this->createNotFoundException('No news found by id ' . $id);
}
if ($request->isMethod('POST')) {
$datedebut = new \Datetime();
$dateDebutFrom = $request->request->all()['form']['dateDebut'];
$datedebut->setDate($dateDebutFrom['year'], $dateDebutFrom['day'], $dateDebutFrom['month']);
$datefin = new \Datetime();
$dateFinFrom = $request->request->all()['form']['dateFin'];
$datefin->setDate($dateFinFrom['year'], $dateFinFrom['day'], $dateFinFrom['month']);
/**/
$articleOLD = new Article();
$articleOLD->setId($id);
$articleOLD->setDateDebut($datedebut);
$articleOLD->setDateFin($datefin);
$articleOLD->setIsDelete('0');
$articleOLD->setLocalisation($localisation);
$articleOLD->setImage($image);
$articleOLD->setTitre($request->request->all()['form']['titre']);
$articleOLD->setSource($request->request->all()['form']['source']);
$articleOLD->setDescription($request->request->all()['form']['description']);
$em->persist($articleOLD);
$em->flush();
return $this->redirect($this->generateUrl("admin_article_list"));
}
return $this->render('AdminBundle:Article:update.html.twig', $build);
}
示例5: YYYYMMDDHHIISStoDate
/**
* Get datetime object from YYYYMMDDHHIISS number
*
* @param $idate
* @return \Datetime
*/
public static function YYYYMMDDHHIISStoDate($idate)
{
$idate = trim($idate);
$date = $idate . "";
$y = (int) substr($date, 0, 4);
$m = (int) substr($date, 4, 2);
$d = (int) substr($date, 6, 2);
$h = (int) substr($date, 8, 2);
$i = (int) substr($date, 10, 2);
$s = (int) substr($date, 12, 2);
$return = new \Datetime();
$return->setDate($y, $m, $d);
$return->setTime($h, $i, $s);
return $return;
}