本文整理汇总了PHP中Datetime::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::format方法的具体用法?PHP Datetime::format怎么用?PHP Datetime::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datetime
的用法示例。
在下文中一共展示了Datetime::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: 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);
}
示例3: getUpdatedAt
/**
* @param string|null $format
*
* @return \Datetime
*/
public function getUpdatedAt($format = null)
{
if ($format) {
return $this->updatedAt->format($format);
}
return $this->updatedAt;
}
示例4: 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;
}
示例5: index
public function index()
{
$user = \Auth::user();
$times = $user->times;
$today = new \Datetime("today");
$factory = new \CalendR\Calendar();
$month = $factory->getMonth($today->format('Y'), $today->format('m'));
return view('dashboard.index', ['user' => $user, 'times' => $times, 'today' => $today, 'factory' => $factory, 'month' => $month]);
}
示例6: getNbOrderByMonth
/**
* Get Nb Order BY Month
*
*/
public function getNbOrderByMonth($user, $dateBegin = null)
{
if (!$dateBegin) {
$dateBegin = new \Datetime('now');
}
$query = $this->getEntityManager()->createQuery("\n SELECT COUNT(o) AS nb, DATE_FORMAT(:dateBegin, '%Y-%m') AS d\n FROM StoreBackendBundle:Order o\n WHERE o.jeweler = :user\n AND MONTH(o.dateCreated) = :month\n AND YEAR(o.dateCreated) = :year\n ")->setParameter('user', $user)->setParameter('dateBegin', $dateBegin->format('Y-m-d'))->setParameter('month', $dateBegin->format('m'))->setParameter('year', $dateBegin->format('Y'));
//exit(var_dump($query->getSingleResult()));
return $query->getSingleResult();
}
示例7: porExtenso
/**
* Retorna Date formatado
*
* @param string|null $date
* @return string|Plugin\Formatar
*/
public function porExtenso($date)
{
$this->setData($date);
$meses = array(1 => "Janeiro", 2 => "Fevereiro", 3 => "Março", 4 => "Abril", 5 => "Maio", 6 => "Junho", 7 => "Julho", 8 => "Agosto", 9 => "Setembro", 10 => "Outubro", 11 => "Novembro", 12 => "Dezembro");
if (!$this->data instanceof \DateTime) {
return 'data inválida!';
}
return $this->data->format('d') . ' de ' . $meses[$this->data->format('n')] . ' de ' . $this->data->format('Y');
}
示例8: indexAction
/**
* Lists all Emission entities.
*/
public function indexAction()
{
$breadcrumbs = $this->get("white_october_breadcrumbs");
$breadcrumbs->addItem('Les émissions');
$breadcrumbs->addItem('Grille des programmes');
$format = $this->get('request')->get('_format');
$timestampDay = 60 * 60 * 24;
$timestampWeek = $timestampDay * 7;
if (!empty($_GET['date'])) {
$start = new \Datetime($_GET['date']);
if ($start->format('W') != 1) {
$start->setISODate($start->format('Y'), $start->format('W'), 1);
}
} elseif (!empty($_GET['week'])) {
$start = new \Datetime();
$start->setISODate($start->format('Y'), $_GET['week'], 1);
}
if (empty($start)) {
$start = new \Datetime('now');
$start->setTime(0, 0);
}
$weekNumber = $start->format('W');
// find programs on current week
$dayNumber = $start->format('w');
if ($dayNumber === 0) {
$start->modify('-6 days');
} elseif ($dayNumber > 1) {
$start->modify('-' . ($dayNumber - 1) . ' days');
}
$stop = clone $start;
$stop->modify('+7 days');
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery("SELECT p FROM ProgramBundle:Program p WHERE p.time_stop < :stop AND p.time_start >= :start AND p.time_start < p.time_stop ORDER BY p.time_start ASC, p.time_stop DESC")->setParameters(array('start' => $start, 'stop' => $stop));
$results = $query->getResult();
$entities = array();
for ($i = 0; $i < 7; $i++) {
$day = clone $start;
$day->modify("+{$i} days");
$entities[] = array('date' => $day, 'tot' => array('label' => 'Tôt', 'desc' => 'Avant 7h00', 'entities' => array()), 'am' => array('label' => 'Matinée', 'desc' => '7h00 - 12h00', 'entities' => array()), 'pm' => array('label' => 'Après-midi', 'desc' => '12h00 - 18h00', 'entities' => array()), 'soir' => array('label' => 'Soirée', 'desc' => '18h00 - 21h00', 'entities' => array()), 'nuit' => array('label' => 'Nuit', 'desc' => 'Après 21h00', 'entities' => array()));
}
foreach ($results as $result) {
$weekDay = $result->getTimeStart()->format('N') - 1;
if ($result->getTimeStart()->format('H:i:s') < '07:00:00') {
$entities[$weekDay]['tot']['entities'][] = $result;
} elseif ($result->getTimeStart()->format('H:i:s') < '12:00:00') {
$entities[$weekDay]['am']['entities'][] = $result;
} elseif ($result->getTimeStart()->format('H:i:s') < '18:00:00') {
$entities[$weekDay]['pm']['entities'][] = $result;
} elseif ($result->getTimeStart()->format('H:i:s') < '21:00:00') {
$entities[$weekDay]['soir']['entities'][] = $result;
} else {
$entities[$weekDay]['nuit']['entities'][] = $result;
}
}
return $this->render(sprintf('ProgramBundle:Program:index.%s.twig', $format), array('entities' => $entities, 'count' => count($results), 'weekNumber' => $weekNumber, 'start' => $start, 'stop' => $stop));
}
示例9: writeMetaMarkdown
protected function writeMetaMarkdown($dir, \Datetime $dt, $slug, $title, $tag)
{
$meta = array('---', 'layout: post', sprintf('title: "%s"', $title), sprintf('date: %s', $dt->format('Y-m-d H:i')), 'comments: false', sprintf('categories: [%s]', implode(', ', array_map(function ($t) {
return sprintf("'%s'", $t);
}, $tag))), '---');
$filename = sprintf("%s-%s.markdown", $dt->format('Y-m-d'), $slug);
$path = $dir . "/" . $filename;
file_put_contents($path, implode("\n", $meta) . "\n");
return $filename;
}
示例10: afterFind
public function afterFind($results, $primary = false)
{
// Mettre la date en Français
$month = array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
foreach ($results as $k => $v) {
if (isset($v['Book'])) {
$date = new Datetime($v['Book']['published']);
$results[$k]['Book']['publicationLe'] = $date->format('d') . ' ' . $month[$date->format('n') - 1] . ' ' . $date->format('Y');
}
}
return $results;
}
示例11: cashAction
/**
* @Route("/cash", name="cash")
* @Method({"GET", "POST"})
*/
public function cashAction(Request $request)
{
$method = $request->getMethod();
if ($method === 'GET') {
$date = new \Datetime('now');
$date = $date->format('Y-m-d');
} else {
$date = $request->request->get('date', null);
}
$em = $this->getDoctrine()->getManager();
is_null($date) ? $date = new \Datetime('now') : ($date = new \Datetime($date));
$appointments = $em->getRepository('AppBundle:Appointment')->getAppointmentsOfDay($date->format('Y-m-d') . ' 00:00:00');
return $this->render('default/cash.html.twig', array('appointments' => $appointments, 'date' => $date->format('Y-m-d')));
}
示例12: render
/**
* Rendering decorator
*
* @param \Datetime $context
* @return string
*/
public function render($context)
{
if (!$context instanceof \Datetime) {
return $context;
}
return $context->format($this->options['format']);
}
示例13: 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");
}
示例14: 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;
}
示例15: isGeekTime
private function isGeekTime(\Datetime $dateTime)
{
if ($dateTime->format('H:i') == '13:37') {
return true;
}
return false;
}