当前位置: 首页>>代码示例>>PHP>>正文


PHP Datetime::setTimestamp方法代码示例

本文整理汇总了PHP中Datetime::setTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::setTimestamp方法的具体用法?PHP Datetime::setTimestamp怎么用?PHP Datetime::setTimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Datetime的用法示例。


在下文中一共展示了Datetime::setTimestamp方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __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;
 }
开发者ID:marmouset,项目名称:funnymals,代码行数:12,代码来源:Duel.php

示例2: initialize

 public function initialize(Controller $controller)
 {
     $this->controller =& $controller;
     if ($this->controller->name != 'Patcher') {
         $this->SettingModel = new Setting();
         $Mushstats = $this->SettingModel->getOption('Mushstats');
         $lastUpdate = new Datetime();
         $lastUpdate->setTimestamp($Mushstats);
         if ($lastUpdate->diff(new Datetime())->d > 6) {
             $this->sendStats();
             $this->SettingModel->setOption('Mushstats', time());
         }
     }
 }
开发者ID:Chaoslan,项目名称:mushraider,代码行数:14,代码来源:MushstatsComponent.php

示例3: 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()));
 }
开发者ID:jojotjebaby,项目名称:Bestfootball,代码行数:47,代码来源:DuelController.php

示例4: getTag3

 /**
  * Returns a tag for tests.
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag
  */
 protected function getTag3()
 {
     $modificationDate = new Datetime();
     $modificationDate->setTimestamp(1343169159);
     return new Tag(array('id' => 9, 'parentTagId' => 47, 'mainTagId' => 0, 'keywords' => array('eng-GB' => 'php'), 'depth' => 2, 'pathString' => '/47/9/', 'modificationDate' => $modificationDate, 'remoteId' => 'a87ff679a2f3e71d9181a67b7542122c', 'alwaysAvailable' => false, 'mainLanguageCode' => 'eng-GB', 'languageCodes' => array('eng-GB')));
 }
开发者ID:umanit,项目名称:TagsBundle,代码行数:11,代码来源:TagsIntegrationTest.php

示例5: php_xmlrpc_decode

/**
 * Takes an xmlrpc value in PHP xmlrpcval object format and translates it into native PHP types.
 *
 * Works with xmlrpc message objects as input, too.
 *
 * Given proper options parameter, can rebuild generic php object instances
 * (provided those have been encoded to xmlrpc format using a corresponding
 * option in php_xmlrpc_encode())
 * PLEASE NOTE that rebuilding php objects involves calling their constructor function.
 * This means that the remote communication end can decide which php code will
 * get executed on your server, leaving the door possibly open to 'php-injection'
 * style of attacks (provided you have some classes defined on your server that
 * might wreak havoc if instances are built outside an appropriate context).
 * Make sure you trust the remote server/client before eanbling this!
 *
 * @author Dan Libby (dan@libby.com)
 *
 * @param xmlrpcval $xmlrpc_val
 * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is
 * @return mixed
 */
function php_xmlrpc_decode($xmlrpc_val, $options = array())
{
    switch ($xmlrpc_val->kindOf()) {
        case 'scalar':
            if (in_array('extension_api', $options)) {
                reset($xmlrpc_val->me);
                list($typ, $val) = each($xmlrpc_val->me);
                switch ($typ) {
                    case 'dateTime.iso8601':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->xmlrpc_type = 'datetime';
                        $xmlrpc_val->timestamp = iso8601_decode($val);
                        return $xmlrpc_val;
                    case 'base64':
                        $xmlrpc_val->scalar = $val;
                        $xmlrpc_val->type = $typ;
                        return $xmlrpc_val;
                    default:
                        return $xmlrpc_val->scalarval();
                }
            }
            if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601') {
                // we return a Datetime object instead of a string
                // since now the constructor of xmlrpcval accepts safely strings, ints and datetimes,
                // we cater to all 3 cases here
                $out = $xmlrpc_val->scalarval();
                if (is_string($out)) {
                    $out = strtotime($out);
                }
                if (is_int($out)) {
                    $result = new Datetime();
                    $result->setTimestamp($out);
                    return $result;
                } elseif (is_a($out, 'Datetime')) {
                    return $out;
                }
            }
            return $xmlrpc_val->scalarval();
        case 'array':
            $size = $xmlrpc_val->arraysize();
            $arr = array();
            for ($i = 0; $i < $size; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->arraymem($i), $options);
            }
            return $arr;
        case 'struct':
            $xmlrpc_val->structreset();
            // If user said so, try to rebuild php objects for specific struct vals.
            /// @todo should we raise a warning for class not found?
            // shall we check for proper subclass of xmlrpcval instead of
            // presence of _php_class to detect what we can do?
            if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' && class_exists($xmlrpc_val->_php_class)) {
                $obj = @new $xmlrpc_val->_php_class();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $obj->{$key} = php_xmlrpc_decode($value, $options);
                }
                return $obj;
            } else {
                $arr = array();
                while (list($key, $value) = $xmlrpc_val->structeach()) {
                    $arr[$key] = php_xmlrpc_decode($value, $options);
                }
                return $arr;
            }
        case 'msg':
            $paramcount = $xmlrpc_val->getNumParams();
            $arr = array();
            for ($i = 0; $i < $paramcount; $i++) {
                $arr[] = php_xmlrpc_decode($xmlrpc_val->getParam($i));
            }
            return $arr;
    }
}
开发者ID:gggeek,项目名称:ggwebservices,代码行数:94,代码来源:xmlrpc.inc.php

示例6: get_datetime

 protected function get_datetime($_t, $is_string = false)
 {
     if ($is_string) {
         $datetime = new \Datetime($_t, $this->timezone);
     } else {
         $_t = $this->ensure_int($_t);
         $datetime = new \Datetime("now", $this->timezone);
         $datetime->setTimestamp($_t);
     }
     return $datetime;
 }
开发者ID:cibulka,项目名称:cibulka-wp-plugin-base,代码行数:11,代码来源:A_Date.php

示例7: isset

                 $slides = Yaml::parse(SLIDESDIR . $sliderName . '/parameters.yml');
                 $slider = Slider::create($sliderName, $slides);
                 $conf = $slider->getConfig();
                 $w = isset($conf['thumbnails']['width']) ? (int) $conf['thumbnails']['width'] : 150;
                 $h = isset($conf['thumbnails']['height']) ? (int) $conf['thumbnails']['height'] : 150;
                 $command = '"' . CONVERT_PATH . "\" -define jpeg:size={$w}x{$h} \"{$img}\" -thumbnail \"{$w}x{$h}^\" -gravity center -extent {$w}x{$h} \"{$thumbFile}\"";
                 shell_exec($command);
             }
             $content = file_get_contents($thumbFile);
         } else {
             $content = file_get_contents($img);
         }
         $response = new Response($content, 200);
         $response->headers->add(array('Content-Type' => 'image/jpeg'));
         $lastModified = new \Datetime();
         $lastModified->setTimestamp(filemtime($img));
         $response->setCache(array('last_modified' => new \Datetime(), 'max_age' => 0, 's_maxage' => 0, 'public' => false));
         return $response;
     } else {
         $response = new Response('', 404);
         $response->setCache(array('last_modified' => new \Datetime(), 'max_age' => 0, 's_maxage' => 0, 'public' => false));
         return $response;
     }
 } else {
     if ($actualReferer) {
         $response = new Response('', 403);
         $response->setCache(array('last_modified' => new \Datetime(), 'max_age' => 0, 's_maxage' => 0, 'public' => false));
         return $response;
     } else {
         return new RedirectResponse($urlGenerator->generate('home'), 301);
     }
开发者ID:PTKGEM,项目名称:EasyImpress,代码行数:31,代码来源:index.php

示例8: ticketlookupAction

 /**
  * @Route("/ticketlookup", name="admin_ticket_lookup")
  */
 public function ticketlookupAction()
 {
     $arr = array();
     $openTicketsForUserNum = 0;
     $arr['total_response'] = $openTicketsForUserNum;
     $yourController = $this->get('adminService');
     $id = $_REQUEST['id'];
     if (array_key_exists('startDate', $_REQUEST)) {
         $raw_startdate = $_REQUEST['startDate'];
         $raw_enddate = $_REQUEST['endDate'];
         // First we need to normalize the dates
         $exp_startdate = explode(".", $raw_startdate);
         $exp_enddate = explode(".", $raw_enddate);
         // Now we need to chop off the last three digits
         $conv_startDate = round($exp_startdate[0] / 1000);
         $conv_endDate = round($exp_enddate[0] / 1000);
         // Now we have a normalized timestamp in unix format.
         // We need to convert that to Datetime
         $startDate = new \Datetime();
         $startDate->setTimestamp($conv_startDate);
         $endDate = new \Datetime();
         $endDate->setTimestamp($conv_endDate);
         $openTicketsForUser = $this->get('doctrine')->getEntityManager('ost')->createQuery("SELECT ticket.ticket_id, cdata.subject, ticket.closed FROM ReportsBundle:ost_ticket ticket, ReportsBundle:ost_ticket__cdata cdata WHERE ticket.closed > '" . $startDate->format('Y-m-d G:i:s') . "' AND ticket.closed < '" . $endDate->format('Y-m-d G:i:s') . "' AND ticket.ticket_id = cdata.ticket_id")->getResult();
         $openTicketsForUserNum = count($openTicketsForUser);
         // Now that we got the results of the table, we can render it.
         // Compile table headers
         $arrr['table_headers'] = array('id', 'Ticket subject', 'Date closed');
         $output = $yourController->__renderTableView($openTicketsForUser, $arrr);
         $arr['table'] = $output;
         $arr['total_response'] = $openTicketsForUserNum;
     }
     $response = new Response(json_encode($arr));
     $response->headers->set('Content-Type', 'application/json');
     return $response;
 }
开发者ID:jeffsacco,项目名称:ostticketreporting,代码行数:38,代码来源:DefaultController.php

示例9: buildForm

 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addModelTransformer(new DateTimeTransformer($options['format'], $options['picker']));
     if ($options['less_than'] || $options['greater_than']) {
         $builder->addEventListener(\Symfony\Component\Form\FormEvents::POST_BIND, function (\Symfony\Component\Form\FormEvent $event) use($options) {
             $form = $event->getForm();
             $date = $form->getData();
             if (!$date) {
                 return;
             }
             $tr = $this->container->get('translator');
             $parent = $form->getParent();
             $object = $parent->getData();
             $admin = $this->container->get('sf.admin.loader')->getAdminByClass($object);
             if ($options['greater_than']) {
                 if (property_exists($object, $options['greater_than'])) {
                     $property = $options['greater_than'];
                     if ($parent->has($property)) {
                         $_date = $parent->get($property)->getData();
                     } else {
                         $_date = $admin->getReflectionProperty($property)->getValue($object);
                     }
                     $label = $admin->getPropertyLabel($property);
                     if ($_date && !$_date instanceof \DateTime) {
                         $error = sprintf("配置错误, 比较目标(%s,%s) 不是日期类型", $label, $property);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     } else {
                         if (!$_date || $date->getTimestamp() < $_date->getTimestamp()) {
                             $error = sprintf("该日期应该大于%s", $label);
                             $form->addError(new \Symfony\Component\Form\FormError($error));
                         }
                     }
                 } else {
                     $_date = date_create_from_format($options['format'], $options['greater_than']);
                     if (!$_date) {
                         $_date = new \Datetime();
                         $_date->setTimestamp(strtotime($options['greater_than']));
                     }
                     if ($_date && $date->getTimestamp() < $_date->getTimestamp()) {
                         $label = $_date->format($options['format']);
                         $error = sprintf("该日期应该大于 %s", $label);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     }
                 }
             }
             if ($options['less_than']) {
                 if (property_exists($object, $options['less_than'])) {
                     $property = $options['less_than'];
                     if ($parent->has($property)) {
                         $_date = $parent->get($property)->getData();
                     } else {
                         $_date = $admin->getReflectionProperty($property)->getValue($object);
                     }
                     $label = $_date->format($options['format']);
                     if ($_date && !$_date instanceof \DateTime) {
                         $error = sprintf("配置错误, 比较目标(%s,%s) 不是日期类型", $label, $property);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     } else {
                         if (!$_date || $date->getTimestamp() > $_date->getTimestamp()) {
                             $error = sprintf("该日期应该小于%s", $label);
                             $form->addError(new \Symfony\Component\Form\FormError($error));
                         }
                     }
                 } else {
                     $_date = date_create_from_format($options['format'], $options['less_than']);
                     if (!$_date) {
                         $_date = new \Datetime();
                         $_date->setTimestamp(strtotime($options['less_than']));
                     }
                     if ($_date && $date->getTimestamp() > $_date->getTimestamp()) {
                         $label = $_date->format($options['format']);
                         $error = sprintf("该日期应该小于 %s", $label);
                         $form->addError(new \Symfony\Component\Form\FormError($error));
                     }
                 }
             }
         });
     }
 }
开发者ID:symforce,项目名称:symforce-admin,代码行数:82,代码来源:DateTimeType.php

示例10: getTag

 /**
  * Returns a tag for tests.
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag
  */
 protected function getTag()
 {
     $modificationDate = new Datetime();
     $modificationDate->setTimestamp(1308153110);
     return new Tag(array('id' => 40, 'parentTagId' => 7, 'mainTagId' => 0, 'keywords' => array('eng-GB' => 'eztags'), 'depth' => 3, 'pathString' => '/8/7/40/', 'modificationDate' => $modificationDate, 'remoteId' => '182be0c5cdcd5072bb1864cdee4d3d6e', 'alwaysAvailable' => false, 'mainLanguageCode' => 'eng-GB', 'languageCodes' => array('eng-GB')));
 }
开发者ID:netgen,项目名称:tagsbundle,代码行数:11,代码来源:TagsTest.php

示例11: _aggSentiment

 protected function _aggSentiment($times, $sec, $format = null)
 {
     $aggTimes = array();
     $sentiment = array();
     $t = 0;
     $dt = new Datetime();
     foreach ($times as $time) {
         if ($t == 0) {
             $t = $time['x'];
         }
         if ($time['x'] > $t + $sec) {
             $aggTimes[] = array('x' => $format == null ? $t : $dt->setTimestamp($t)->format($format), 'y' => array_sum($sentiment) / sizeof($sentiment));
             $t += $sec;
             $sentiment = array();
         }
         $sentiment[] += $time['y'];
     }
     return $aggTimes;
 }
开发者ID:NickDario,项目名称:elevencastles,代码行数:19,代码来源:CastleController.php

示例12: get_time_from_db

 /**
  * Return a 24hr time to 12 hr time with AM / PM
  * @param database time
  * @return string
  */
 public static function get_time_from_db($time)
 {
     $date = new Datetime();
     $date->setTimestamp(strtotime($time));
     return $date->format('h:i:s A');
 }
开发者ID:shashin62,项目名称:abc_audit,代码行数:11,代码来源:date_tool.php


注:本文中的Datetime::setTimestamp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。