本文整理汇总了PHP中Datetime类的典型用法代码示例。如果您正苦于以下问题:PHP Datetime类的具体用法?PHP Datetime怎么用?PHP Datetime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Datetime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sync_orders
private function sync_orders($woo_id, $url, $start_at, $batch_size = 100)
{
echo "Syncing with {$url}.\n";
$mongo_orders = $this->mongo_db->selectCollection('orders');
$t = new DateTime("@{$start_at}");
$start_at_t = $t->format(DateTime::RFC3339);
$start_at_t = mb_substr($start_at_t, 0, mb_strlen($start_at_t) - 6) . 'Z';
$pages = $at_page = 1;
while ($at_page <= $pages) {
$result = $this->wcc->orders->get(null, array('filter[updated_at_min]' => $start_at_t, 'filter[limit]' => $batch_size, 'filter[offset]' => $at_page * $batch_size));
if (isset($result['http']['response']['headers']['X-WC-TotalPages'])) {
$pages = (int) $result['http']['response']['headers']['X-WC-TotalPages'];
}
if (isset($result['orders'])) {
foreach ($result['orders'] as $order) {
$created_at = new DateTime($order['created_at']);
$updated_at = new Datetime($order['updated_at']);
$completed_at = new DateTime($order['completed_at']);
$order['shoplab_user_id'] = $woo_id;
$order['created_at_ts'] = $created_at->getTimestamp();
$order['updated_at_ts'] = $updated_at->getTimestamp();
$order['completed_at_ts'] = $completed_at->getTimestamp();
$mongo_orders->update(array('shoplab_user_id' => $order['shoplab_user_id'], 'order_number' => $order['order_number']), $order, array('upsert' => true));
}
}
if (0 < $pages) {
echo "Fetched page {$at_page} (batch size {$batch_size}) of {$pages}.\n";
} else {
echo "Nothing more to fetch.\n";
}
$at_page++;
}
}
示例2: transform
/**
* Transform un objet DateTime en timestamp
* @param Datetime|null $datetime
* @return array
*/
public function transform($datetime)
{
if (!$datetime instanceof \DateTime) {
return null;
}
return $datetime->format("U");
}
示例3: registerVisistor
/**
* Save or update a visitor.
*/
public function registerVisistor($ipAdress, $pageName)
{
$isAdmin = $this->securityContext->isGranted(Constants::ROLE_ADMIN);
if ($isAdmin) {
$dateNow = new \Datetime();
$currentPage = $this->getPageByName($pageName);
$totalVisitsPage = $this->getPageByName(Constants::TOTAL_PAGE_NAME);
// On cherche le visiteur dans la BDD via son adresse
$visitor = $this->findVisitorByIpAddress($ipAdress);
if ($visitor !== null) {
// Si le visiteur est d�j� connu et sa derni�re connection date de plus
// de 5 minutes on consid�re que c'est une nouvelle visite
$seconds = $dateNow->getTimestamp() - $visitor->getLastConnection()->getTimestamp();
if ($seconds > 5 * 60) {
// new visit
$totalVisitsPage->incrementVisits();
$currentPage->incrementVisits();
}
// On met simplement � jour sa date de derni�re connection
$visitor->setLastConnection($dateNow);
} else {
// nouveau visiteur
$totalVisitsPage->incrementVisits();
$currentPage->incrementVisits();
// On enregistre le visiteur
$visitor = $this->createVisitor($ipAdress);
}
if (!$visitor->hasAlreadyVisitedPage($currentPage)) {
$visitor->addPage($currentPage);
}
}
// save or update all entities
$this->em->flush();
return $this;
}
示例4: EnregistrementAction
/**
* @Route("/admin/page/template/enregistrer", name = "enregistrer_template" , defaults={} )
* @Template
* @I18nDoctrine
*/
public function EnregistrementAction(Request $request)
{
$code = $request->request->get('code');
$template = $request->request->get('template');
if ($template == "" || $template == NULL) {
die("impossible");
}
$dir = $this->dir_theme . $this->container->getParameter('front_theme') . "/";
$file = $template;
if (file_exists($dir . $file)) {
$now = new \Datetime();
$backup_dir = $dir . $now->format("Y-m-d");
if (!is_dir($backup_dir)) {
mkdir($backup_dir);
}
if (!copy($dir . $file, $backup_dir . "/" . $now->format("H:i:s") . "_" . $file)) {
die("Copy impossible");
}
$monfichier = fopen($dir . $file, 'w');
fseek($monfichier, 0);
fputs($monfichier, $code);
fclose($monfichier);
}
return new Response('ok');
}
示例5: getUpdatedAt
/**
* @param string|null $format
*
* @return \Datetime
*/
public function getUpdatedAt($format = null)
{
if ($format) {
return $this->updatedAt->format($format);
}
return $this->updatedAt;
}
示例6: loadSnapshots
/**
* {@inheritdoc}
*/
public function loadSnapshots(SiteInterface $site)
{
$now = new \Datetime();
$query = $this->getEntityManager()->createQuery(sprintf('
SELECT s,p
FROM %s s
INNER JOIN s.page p
WHERE
s.enabled = 1
AND
s.site = %d
AND
s.publicationDateStart <= \'%s\'
AND
( s.publicationDateEnd IS NULL OR s.publicationDateEnd >= \'%s\' )
ORDER BY s.position ASC
', $this->class, $site->getId(), $now->format('Y-m-d H:i:s'), $now->format('Y-m-d H:i:s')));
$query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_INNER_JOIN, true);
$query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
$query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $site->getLocale());
$snapshots = array();
foreach ($query->execute() as $snap) {
$snapshots[$snap->getPage()->getId()] = $snap;
}
$this->snapshots = $snapshots;
}
示例7: opml_export
/**
* Generate an OPML file to export the feeds.
*
* @copyright Heavily based on a function from FreshRSS.
*/
function opml_export($feeds)
{
$tags = array();
foreach ($feeds as $key => $feed) {
if (empty($feed['tags'])) {
$tags['untagged'][] = $key;
continue;
}
foreach ($feed['tags'] as $tag) {
$tags[$tag][] = $key;
}
}
$now = new Datetime();
$txt = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$txt .= '<opml version="2.0">' . PHP_EOL;
$txt .= "\t" . '<head>' . PHP_EOL;
$txt .= "\t\t" . '<title>Export of Freeder feeds</title>' . PHP_EOL;
$txt .= "\t\t" . '<dateCreated>' . $now->format(DateTime::RFC822) . '</dateCreated>' . PHP_EOL;
$txt .= "\t" . '</head>' . PHP_EOL;
$txt .= "\t" . '<body>' . PHP_EOL;
foreach ($tags as $tag => $id_feeds) {
$txt .= "\t\t" . '<outline text="' . $tag . '">' . PHP_EOL;
foreach ($id_feeds as $id_feed) {
$website = multiarray_search('rel', 'alternate', $feeds[$id_feed]['links'], '');
if (!empty($website)) {
$website = 'htmlUrl="' . htmlspecialchars($website['href'], ENT_COMPAT, 'UTF-8') . '"';
}
$txt .= "\t\t\t" . '<outline text="' . htmlspecialchars($feeds[$id_feed]['title'], ENT_COMPAT, 'UTF-8') . '" type="rss" xmlUrl="' . htmlspecialchars($feeds[$id_feed]['url'], ENT_COMPAT, 'UTF-8') . '" ' . $website . ' description="' . htmlspecialchars($feeds[$id_feed]['description'], ENT_COMPAT, 'UTF-8') . '" />' . PHP_EOL;
}
$txt .= "\t\t" . '</outline>' . PHP_EOL;
}
$txt .= "\t" . '</body>' . PHP_EOL;
$txt .= '</opml>';
return $txt;
}
示例8: isGeekTime
private function isGeekTime(\Datetime $dateTime)
{
if ($dateTime->format('H:i') == '13:37') {
return true;
}
return false;
}
示例9: diffDias
public function diffDias($data)
{
$date = new \Datetime(null);
$hoje = $date->getTimestamp() + $date->getOffset();
$diff = strtotime($data) - $hoje;
return floor($diff / (24 * 60 * 60));
}
示例10: actionExportar
public function actionExportar()
{
// get your HTML raw content without any layouts or scripts
if (isset($_COOKIE['pcbuilder_cart'])) {
$total = 0;
$pcbuilder_cart = unserialize($_COOKIE['pcbuilder_cart']);
if (count($pcbuilder_cart) > 0) {
$pcbuilder_cart = Yii::$app->PCBuilder->array_sort($pcbuilder_cart, 'categoria', 'SORT_ASC');
foreach ($pcbuilder_cart as $i => $peca) {
$modelPeca = Pecas::findOne($peca['peca']);
$pecas[] = ['id' => $modelPeca['id'], 'cookieID' => $i, 'nome' => $modelPeca['nome'], 'loja' => $modelPeca['loja'], 'link_externo' => $modelPeca['link_externo'], 'preco' => $modelPeca['preco'][0]['preco']];
$total = $total + $modelPeca['preco'][0]['preco'];
}
}
} else {
echo "Nada para salvar!";
exit;
}
if (count($pecas) > 0) {
$content = $this->renderPartial('_pdf', ['pecas' => $pecas, 'total' => $total]);
$date = new \Datetime(null);
$hoje = $date->getTimestamp() + $date->getOffset();
// setup kartik\mpdf\Pdf component
$pdf = new Pdf(['mode' => Pdf::MODE_BLANK, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_DOWNLOAD, 'content' => $content, 'filename' => 'PC Builder - Lista de Peças - ' . date("d.m.Y H.i.s", $hoje) . '.pdf', 'options' => ['title' => 'PC Builder - Lista de Peças - ' . date("d/m/Y H:i:s", $hoje), 'defaultheaderline' => 0, 'setAutoTopMargin' => 'stretch'], 'methods' => ['SetHeader' => ['' . '<table width="100%">' . '<tr>' . '<td width="75%"><a target="_blank" href="http://www.brunodeoliveira.com"><img width="100px" src="imgs/logo.png"></a></td>' . '<td width="25%" valign="bottom" style="text-align: right">Salvo em<br /><small>' . date("d/m/Y H:i:s") . '</small></td>' . '<tr/>' . '</table>' . ''], 'SetFooter' => ['Obrigado por utilizar o PC Builder - Desenvolvido por Bruno de Oliveira - Página {PAGENO}']]]);
return $pdf->render();
}
}
示例11: getByDate
public function getByDate(\Datetime $date1, \Datetime $date2)
{
$queryBuilder = $this->createQueryBuilder('a');
$queryBuilder->where('a.date BETWEEN :date1 AND :date2')->setParameter('date1', $date1->format('Y-m-d'))->setParameter('date2', $date2->format('Y-m-d'));
$query = $queryBuilder->getQuery();
return $query->getResult();
}
示例12: toDateTime
public function toDateTime()
{
$dateTime = new \Datetime();
$dateTime->setDate($this->year, $this->month, $this->day);
$dateTime->setTime(0, 0, 0);
return $dateTime;
}
示例13: render
/**
* Rendering decorator
*
* @param \Datetime $context
* @return string
*/
public function render($context)
{
if (!$context instanceof \Datetime) {
return $context;
}
return $context->format($this->options['format']);
}
示例14: relativeDate
/**
* Helpfer function relativeDate()
*/
function relativeDate($date, $args = array())
{
// default for $args
$defaults = array('lang' => count(site()->languages()) >= 1 ? site()->language()->code() : c::get('relativedate.lang', 'en'), 'length' => c::get('relativedate.length', 2), 'threshold' => c::get('relativedate.threshold', false), 'fuzzy' => c::get('relativedate.fuzzy', true), 'format' => c::get('relativedate.format', 'd.m.Y'));
$args = array_merge($defaults, $args);
// check if $date is a timestamp
if (RelativeDate::isTimestamp($date)) {
$date = date(DATE_ATOM, $date);
}
// only convert to relative if time difference no exceeds threshold
if ($args['threshold'] === false or abs(strtotime($date) - time()) <= $args['threshold']) {
try {
$relative = new RelativeDate($date, $args);
$result = $relative->get($args['length']);
} catch (Exception $e) {
$result = $date;
}
} else {
$result = $date;
}
// if we had no change to date due to any bug or exceeding threshold
if ($result === $date) {
$date = new Datetime($date);
$result = $date->format($args['format']);
}
return $result;
}
示例15: setUp
public function setUp()
{
parent::setUp();
$date = new Datetime();
$dmax = $date->format("Y-m-d H:i:s");
$date->modify('-6 month');
$dmin = $date->format("Y-m-d H:i:s");
$databoxes = self::$DI['app']->getDataboxes();
$ret = [];
foreach ($databoxes as $databox) {
$colls = $databox->get_collections();
$rett = [];
foreach ($colls as $coll) {
$rett[$coll->get_coll_id()] = $coll->get_coll_id();
}
$ret[$databox->get_sbas_id()] = implode(',', $rett);
}
foreach ($ret as $sbasid => $collections) {
$report = new module_report_connexion(self::$DI['app'], $dmin, $dmax, $sbasid, $collections);
if (!$this->report instanceof module_report) {
$this->report = $report;
} elseif ($report->getTotal() > $this->report->getTotal()) {
$this->report = $report;
}
}
$this->report->setFilter([['f' => 'user', 'o' => '=', 'v' => 'admin'], ['f' => 'ddate', 'o' => 'LIKE', 'v' => '*'], ['f' => '1', 'o' => 'OR', 'v' => '1']]);
$this->report->setUser_id(self::$DI['user']->getId());
$this->report->setOrder('user', 'ASC');
$this->filter = new module_report_sqlfilter(self::$DI['app'], $this->report);
}