本文整理汇总了PHP中Datetime::getTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::getTimestamp方法的具体用法?PHP Datetime::getTimestamp怎么用?PHP Datetime::getTimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datetime
的用法示例。
在下文中一共展示了Datetime::getTimestamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: diffDias
public function diffDias($data)
{
$date = new \Datetime(null);
$hoje = $date->getTimestamp() + $date->getOffset();
$diff = strtotime($data) - $hoje;
return floor($diff / (24 * 60 * 60));
}
示例2: getParams
public function getParams()
{
$params = ['get_sent_offers' => $this->getSentOffers, 'get_received_offers' => $this->getReceivedOffers, 'get_descriptions' => $this->getDescriptions, 'active_only' => $this->activeOnly, 'historical_only' => $this->historicalOnly];
empty($this->language) ?: ($params['language'] = $this->language);
empty($this->timeHistoricalCutoff) ?: ($params['time_historical_cutoff'] = $this->timeHistoricalCutoff->getTimestamp());
return $params;
}
示例3: 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();
}
}
示例4: 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++;
}
}
示例5: 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;
}
示例6: normalizeDateTime
/**
* Normalizes DateTime object
*
* @param null|\Datetime $utcDatetime
*
* @return null|string
*/
protected function normalizeDateTime($utcDatetime)
{
if (!$utcDatetime instanceof \DateTime) {
return;
}
$datetime = new \DateTime();
$datetime->setTimestamp($utcDatetime->getTimestamp());
return $datetime->format('Y-m-d g:i:s A');
}
示例7: isPublished
/**
* @return bool
*/
public function isPublished()
{
$isStatusPublished = parent::isPublished();
$currentTimestamp = time();
if ($isStatusPublished && (null !== $this->publicationDate && $currentTimestamp >= $this->publicationDate->getTimestamp())) {
return true;
}
return false;
}
示例8: formatDate
/**
* formatDate
* Format a datetime to a readable date according to the locale
* @param \Datetime $date
*/
public function formatDate(\Datetime $date)
{
$locale = $this->container->getParameter('locale');
$format = "%A, %#d %B %Y";
// windows does not support %e so we put %#d
if (substr($locale, 0, 2) === "fr") {
$format = str_replace(',', '', $format);
}
return strftime($format, $date->getTimestamp());
}
示例9: testGetTimeStamp
/**
* @covers WindowsAzure\MediaServices\Models\TaskHistoricalEvent::getTimeStamp
* @covers WindowsAzure\MediaServices\Models\TaskHistoricalEvent::__construct
*/
public function testGetTimeStamp()
{
// Setup
$options = array('TimeStamp' => '2013-11-27');
$time = new \Datetime($options['TimeStamp']);
$histEvent = TaskHistoricalEvent::createFromOptions($options);
// Test
$result = $histEvent->getTimeStamp();
// Assert
$this->assertEquals($time->getTimestamp(), $result->getTimestamp());
}
示例10: __construct
public function __construct()
{
$this->dateDeb = new \Datetime();
//$this->dateFin = new \Datetime();
$dateBase = new \Datetime();
$duration = 3600 * 24 * 3;
$endtimestamp = $dateBase->getTimestamp() + $duration;
$dateBase->setTimestamp($endtimestamp);
$this->dateFin = $dateBase;
$this->voteA = 0;
$this->voteB = 0;
}
示例11: actionEventos
public function actionEventos($from, $to)
{
$date = new \Datetime(null);
$hoje = $date->getTimestamp() + $date->getOffset();
$de = date("Y-m-d", $from / 1000);
$para = date("Y-m-d", $to / 1000);
$model = Eventos::find()->joinWith('atividade')->where(['>=', 'd_ini', $de])->orWhere(['<=', 'd_ter', $de])->orWhere(['<=', 'd_ter', $para])->andWhere(['atividades.empresa_id' => Yii::$app->session->get('empresa')])->all();
$d = ['success' => 1];
foreach ($model as $dados) {
$d['result'][] = ['id' => $dados['id'], 'title' => $dados['atividade']['atividade'], 'url' => Url::to(['evento/visualizar', 'id' => $dados['id']]), 'class' => Yii::$app->AgobUtils->cssStatus($dados['status'], $dados['d_ter']), 'start' => strtotime($dados['d_ini']) . '000', 'end' => strtotime($dados['d_ter']) . '000', 'dias' => Yii::$app->AgobUtils->diffDias($dados['d_ter']), 'status' => $dados['status']];
}
echo json_encode($d);
}
示例12: searchDateAction
public function searchDateAction()
{
$form = $this->_getDateSearchForm();
if ($form->isValid() && ($data = $form->getFilteredData())) {
try {
$from = new \Datetime($data['from']);
$to = new \Datetime($data['to']);
} catch (\Exception $e) {
$this->addFlash('error', 'Invalid input for dates!');
return $this->redirectToReferer();
}
return $this->redirectToRoute('ms.cp.discount.listing.active.date', array('fromTimestamp' => $from->getTimestamp(), 'toTimestamp' => $to->getTimestamp()));
}
}
示例13: historiqueAction
public function historiqueAction()
{
$source = null;
$cible = null;
$request = $this->getRequest();
$montant = "";
$repository = $this->getDoctrine()->getManager()->getRepository('ConvertDeviseBundle:Devise');
$devise = $repository->findAll();
// On vérifie qu'elle est de type POST
if ($request->getMethod() == 'POST') {
$source = $request->request->get('_source');
$cible = $request->request->get('_cible');
$montant = $request->request->get('_montant');
$sourcecible = $source . $cible;
$this->getparamAction();
//connexion entre api yahoo et application
$this->convertAction($sourcecible);
$t = new \Datetime();
$t->getTimestamp();
$datedemande = $t;
$etatip = 1;
//adresse ip du client
$ipdclient = $_SERVER["REMOTE_ADDR"];
$this->getclientAction($ipdclient, $datedemande);
$cour = $this->cour;
$nbdemande = 1;
$hist = new Historique();
$hist->setSource($source);
$hist->setCible($cible);
$hist->setDatedemande($datedemande);
$hist->setNbdemande($nbdemande);
$hist->setCour($cour);
$hist->setMontant($montant);
$hist->setIpdclient($ipdclient);
if ($this->bloque == true) {
$etatip = 0;
$hist->setEtatip($etatip);
$em = $this->getDoctrine()->getManager();
$em->persist($hist);
$em->flush();
return $this->render('ConvertDeviseBundle:Devise:blacklist.html.twig');
} else {
$hist->setEtatip($etatip);
$em = $this->getDoctrine()->getManager();
$em->persist($hist);
$em->flush();
}
}
return $this->render('ConvertDeviseBundle:Devise:index.html.twig', array('devise' => $devise, 'cour' => $this->cour, 'montant' => $montant, 'source' => $source, 'cible' => $cible));
}
示例14: getTimeAgo
public function getTimeAgo(\Datetime $date)
{
$time = time() - $date->getTimestamp();
$units = array(31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second');
$aMap = array("year" => "a", "month" => "a", "week" => "a", "day" => "a", "hour" => "an", "minute" => "a", "second" => "a");
foreach ($units as $unit => $label) {
if ($time < $unit) {
continue;
}
$numberOfUnits = floor($time / $unit);
$a = $aMap[$label];
return $label == 'second' ? 'a few seconds ago' : ($numberOfUnits > 1 ? $numberOfUnits : $a) . ' ' . $label . ($numberOfUnits > 1 ? 's' : '') . ' ago';
}
}
示例15: createAction
public function createAction(request $request, $username)
{
$em = $this->getDoctrine()->getManager();
//we get the host and the invited user
$host = $this->container->get('security.context')->getToken()->getUser();
$guest = $em->getRepository('BFUserBundle:User')->findOneByUsername($username);
//we check that the host and guest are not the same person
if ($host == $guest) {
throw new NotFoundHttpException("You can't create a duel against yourself.");
}
//we create a new duel and set the users to the duel
$date = new \Datetime();
$duration = 7 * 24 * 60 * 60;
$endtimestamp = $date->getTimestamp() + $duration;
$date->setTimestamp($endtimestamp);
$duel = new Duel();
$duel->setBeginDate(new \Datetime())->setEndDate($date)->setAccepted('0')->setCompleted('0')->setHostCompleted('0')->setGuestCompleted('0')->setHost($host)->setGuest($guest)->setType('duel')->addUser($host)->addUser($guest);
//getting the code for the duel
$service = $this->container->get('bf_site.randomcode');
$code = $service->generate('duel');
$duel->setCode($code);
$message = 'You received an invitation for a duel from ' . $host->getUsername();
$link = $this->generateUrl('bf_site_profile_duels');
//we create a notification for the guest.
$service = $this->container->get('bf_site.notification');
$notification = $service->create($guest, $message, $duel, $link);
$request = $this->get('request');
if ($request->getLocale() == 'en') {
$form = $this->get('form.factory')->create(new DuelType(), $duel);
} elseif ($request->getLocale() == 'fr') {
$form = $this->get('form.factory')->create(new DuelFRType(), $duel);
}
if ($form->handleRequest($request)->isValid()) {
//we check if the user wants to receive a mail. If so, we send him an email.
$em = $this->getDoctrine()->getManager();
$em->persist($notification);
$em->persist($duel);
$em->flush();
if ($guest->getMailDuel() === true) {
$message = \Swift_Message::newInstance()->setSubject($host->getUsername() . ' invited you for a duel on bestfootball')->setFrom('bestfootball@bestfootball.fr')->setTo($guest->getEmail())->setBody($this->renderView('Emails/duel.html.twig', array('host' => $host, 'guest' => $guest, 'duel' => $duel)), 'text/html');
$this->get('mailer')->send($message);
}
$this->addFlash('success', 'Your invitation for a duel has been send to ' . $guest->getUsername() . ' you will have to wait for ' . $guest->getUsername() . ' to accept it.');
return $this->redirect($this->generateUrl('bf_site_profile', array('username' => $guest->getUsername())));
}
return $this->render('BFSiteBundle:Duel:create.html.twig', array('form' => $form->createView()));
}