本文整理汇总了PHP中Datetime::setTimezone方法的典型用法代码示例。如果您正苦于以下问题:PHP Datetime::setTimezone方法的具体用法?PHP Datetime::setTimezone怎么用?PHP Datetime::setTimezone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datetime
的用法示例。
在下文中一共展示了Datetime::setTimezone方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: newsSentiment
public function newsSentiment()
{
$feeds = Input::get('feeds', array());
$minOffset = Input::get('minOffset', 0);
$agg = json_decode(Input::get('agg', '["hour", "day", "month"]'));
$db = DB::connection('rss');
$feeds = DB::connection('rss')->select('SELECT * FROM feeds');
$stories = DB::connection('rss')->select('SELECT * FROM stories order by date desc');
$aFeeds = array();
foreach ($feeds as $feed) {
$feed->stories = array();
$aFeeds[$feed->id] = $feed;
}
foreach ($stories as $story) {
$date = date_create_from_format('Y-m-d_H-i-s', $story->date);
$aFeeds[$story->feeds_id]->stories[] = array('id' => (int) $story->id, 'title' => $story->title, 'date' => $date->sub(new DateInterval('PT8H')), 'sentiment' => (int) $story->sentiment);
}
$now = new Datetime();
$now->setTimezone(new DateTimeZone('America/Los_Angeles'));
// $now_year = $now->format('Y');
// $now_month = $now->format('m');
// $now_day = $now->format('d');
//
//
// $hourlist = array();
// $daylist=array();
// $monthlist = array();
// for($h=0;$h<24;$h++){
// $hourlist[] = array(
// 'x' => $h,
// 'y' => 0
// );
// }
// for($d=0;$d<date('t');$d++){
// $daylist[$d] = array(
// 'x' => $d,
// 'y' => 0
// );
// }
// for($m=0;$m<12;$m++){
// $monthlist[$m] = array(
// 'x' => $m,
// 'y' => 0
// );
// }
$unixlist = array();
$aSentimentTime = array();
foreach ($aFeeds as $feed) {
foreach ($feed->stories as $story) {
$aSentimentTime[] = array('x' => $story['date']->getTimestamp(), 'y' => $story['sentiment']);
}
}
usort($aSentimentTime, function ($a, $b) {
return $a['x'] > $b['x'];
});
$timeset = $this->_aggSentiment($aSentimentTime, 3600 * 3, 'Y-m-d-H-i-s');
echo json_encode(array('ulist' => $timeset));
}
示例2: array
<?php
ini_set('display_errors', 1);
require_once 'TwitterAPIExchange.php';
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array('oauth_access_token' => "998032536-YHb8IcLPlQbigJgRoP8VowBLADwH9RgBZZZ6mY0J", 'oauth_access_token_secret' => "SW6g2sKE4HPOhQg9WSLySXrnVxNo9xDxwI6CsSij4uGKh", 'consumer_key' => "i6qskwGhaXjVHC51u2MYO7b9P", 'consumer_secret' => "Oqna2t4eB5oelVKZaay8crIEsPxTnNllVROAy8zqAglNmY2QIZ");
/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=#parisattacks&count=50';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$api_response = $twitter->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest();
$tweetData = json_decode($api_response);
foreach ($tweetData->statuses as $tweet) {
$date = new Datetime($tweet->created_at);
$date->setTimezone(new DateTimeZone('America/New_York'));
echo "<div class='twitteruserphoto'><a href='http://twitter.com/{$tweet->user->screen_name}' target='_blank'><img src='{$tweet->user->profile_image_url}'></a></div>";
echo "<div class='twittername'><a href='http://twitter.com/{$tweet->user->screen_name}' target='_blank'>{$tweet->user->name}</a></div>";
echo "<div class='twitteruser'><a href='http://twitter.com/{$tweet->user->screen_name}' target='_blank'>@{$tweet->user->screen_name}</a></div>";
echo "<div class='twittertext'>{$tweet->text}</div>";
echo "<div class='twittertime'><a href='http://twitter.com/{$tweet->user->screen_name}/status/{$tweet->id_str}' target='_blank'>{$date->format('M jS g:i:s a ')}</a></div>";
echo "<div class='twitterphoto'><a href='{$tweet->entities->media[0]->media_url}' target='_blank'><img src='{$tweet->entities->media[0]->media_url}' style='max-width:100%'></a></div>";
echo "<div class='twitterline' style='width:100% height:1px'></div>";
echo "<script>pageComplete();</script>";
}
?>
<!-- javacript -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- <script src="js/smoothstate.js"></script>
示例3: fromVObject
/**
* Updates this Calendar2 object with data from the given VEVENT
*
* The returned object must be save()d before it is persistent.
* This also means that additional changes can be made before any database calls are made.
*
* @param Sabre_VObject_Component $vevent The vevent component
*
* @throws Exception If the provided component is not a vevent
*
* @return void
*/
public function fromVObject(Sabre_VObject_Component $vevent)
{
if (strtolower($vevent->name) !== 'vevent') {
throw new Exception("Invalid type of vobject_component passed to Calendar2_Models_Calendar2::fromVobject ({$vevent->name})");
}
// Workarounds for missing features. We currently don't support locale-time (we just assume it's the user's
// usual timzeone) or date values without time (we just assume 0800 - 2000 there).
if (!is_null($vevent->dtstart['VALUE']) && $vevent->dtstart['VALUE']->value === 'DATE') {
// No T means it's only a date. iCalendar dicates that dtend must be a date, too.
$vevent->dtstart->value .= 'T080000';
unset($vevent->dtstart['VALUE']);
// Caldav end dates are not inclusive
$end = new Datetime($vevent->dtend->value);
$end->sub(new DateInterval('P1D'));
$vevent->dtend->value = $end->format('Ymd') . 'T200000';
unset($vevent->dtend['VALUE']);
}
$utc = new DateTimezone('UTC');
$timezone = null;
if ('Z' === substr($vevent->dtstart->value, -1)) {
$timezone = $utc;
} else {
if (!is_null($vevent->dtstart['tzid'])) {
$timezone = new DateTimeZone($vevent->dtstart['tzid']->value);
} else {
$timezone = Phprojekt_User_User::getUserDateTimeZone();
}
}
// 0-1
// handled:
// last-mod, description, dtstart, location, summary, uid
// not handled
// class, created, geo, organizer, priority, dtstamp, seq, status, transp, url, recurid
//
// none or one of these two
// dtend, duration (only assumes dtend case for now)
//
// 0 - n
// TODO: Check how we can handle these. Maybe just concat them?
// handling: (only one is handled atm, though)
// comment, rrule
// not handling:
// attach, attendee, categories, contact, exdate, exrule, rstatus, related, resources, rdate, x-prop
$mappable = array(array('veventkey' => 'SUMMARY', 'ourkey' => 'summary', 'default' => '_'), array('veventkey' => 'LOCATION', 'ourkey' => 'location', 'default' => ''), array('veventkey' => 'DESCRIPTION', 'ourkey' => 'description', 'default' => ''), array('veventkey' => 'COMMENT', 'ourkey' => 'comments'), array('veventkey' => 'UID', 'ourkey' => 'uid'), array('veventkey' => 'LAST-MODIFIED', 'ourkey' => 'lastModified'), array('veventkey' => 'RRULE', 'ourkey' => 'rrule', 'default' => ''));
foreach ($mappable as $m) {
if (isset($vevent->{$m}['veventkey'])) {
$this->{$m}['ourkey'] = $vevent->{$m}['veventkey'];
} else {
if (array_key_exists('default', $m)) {
$this->{$m}['ourkey'] = $m['default'];
}
}
}
$start = new Datetime($vevent->dtstart->value, $timezone);
$start->setTimezone($utc);
$this->start = Phprojekt_Converter_Time::utcToUser($start->format('Y-m-d H:i:s'));
if ($vevent->dtend) {
$end = new Datetime($vevent->dtend->value, $timezone);
} else {
if ($vevent->duration) {
$duration = new DateInterval($vevent->duration->value);
$end = clone $start;
$end->add($duration);
}
}
$end->setTimezone($utc);
$this->end = Phprojekt_Converter_Time::utcToUser($end->format('Y-m-d H:i:s'));
}
示例4: postProcess
//.........这里部分代码省略.........
$iname = $_FILES[$ub_image_name]['name'];
$this->b_image = "http://" . _MEDIA_SERVER_1_ . '/img/' . $dir . $b_id . '-' . $iname;
$hasImage = true;
}
}
if (!$hasImage) {
$this->_errors[] = "Unable to upload banner image";
}
$b_id = uniqid();
$hasImage = true;
if (isset($_FILES) && isset($_FILES['upnext_image'])) {
$dir = 'mails/';
$ub_image_name = "upnext_image";
$ub_image_ext = substr($_FILES['upnext_image']['type'], strpos($_FILES['upnext_image']['type'], "/") + 1);
$res = Tools::uploadImage($b_id, $ub_image_name, $dir, $ub_image_ext);
if (!$res) {
if ($this->id_campaign === 0) {
$this->u_image = '';
} else {
$res = $db->ExecuteS("select upnext_image from ps_mailers where id_campaign = {$this->id_campaign}");
//echo "<pre>"; print_r( $res ); exit;
$this->u_image = $res[0]['upnext_image'];
if (empty($this->u_image)) {
$hasImage = false;
}
}
} else {
$iname = $_FILES[$ub_image_name]['name'];
$this->u_image = "http://" . _MEDIA_SERVER_1_ . '/img/' . $dir . $b_id . '-' . $iname;
$hasImage = true;
}
}
if (!$hasImage) {
$this->_errors[] = "Unable to upload Up-Next image";
}
$this->assignToSmarty();
$this->fillProductsInformation();
if ($_POST['psubmit'] && $_POST["psubmit"] === "Preview") {
if ($this->id_campaign === 0) {
// new campaign
$sql = "insert into ps_mailers(campaign_name, utm_source, utm_medium, utm_campaign,\n banner_image,upnext_image, write_up, banner_link, pid_l, pids,id_employee, template,action_link,subject) values (" . "'" . pSQL($this->c_name) . "'," . "'" . pSQL($this->utm_s) . "'," . "'" . pSQL($this->utm_m) . "'," . "'" . pSQL($this->utm_c) . "'," . "'" . pSQL($this->b_image) . "'," . "'" . pSQL($this->u_image) . "'," . "'" . pSQL($this->write_up) . "'," . "'" . pSQL($this->b_url) . "'," . "" . $this->pid_l . "," . "'" . pSQL(implode($this->pid, ",")) . "'," . "" . $id_employee . "," . "'" . pSQL($this->template) . "'," . "'" . pSQL($this->a_link) . "'," . "'" . pSQL($this->subject) . "'" . ")";
$db->Execute($sql);
$this->id_campaign = $db->Insert_ID();
} else {
// edit or preview old campaign
$sql = "update ps_mailers set \n campaign_name = '" . pSQL($this->c_name) . "',\n utm_source = '" . pSQL($this->utm_s) . "',\n utm_medium = '" . pSQL($this->utm_m) . "',\n utm_campaign = '" . pSQL($this->utm_c) . "',\n banner_image = '" . pSQL($this->b_image) . "',\n upnext_image = '" . pSQL($this->u_image) . "',\n write_up = '" . pSQL($this->write_up) . "',\n banner_link = '" . pSQL($this->b_url) . "',\n pid_l = {$this->pid_l},\n pids = '" . pSQL(implode($this->pid, ",")) . "',\n template = '" . pSQL($this->template) . "',\n action_link = '" . pSQL($this->a_link) . "',\n subject = '" . pSQL($this->subject) . "'\n where id_campaign = {$this->id_campaign}";
$db->Execute($sql);
}
$previewMail = $smarty->fetch(_PS_THEME_DIR_ . $this->template);
$previewMailTxt = $smarty->fetch(_PS_THEME_DIR_ . 'text_' . $this->template);
$smarty->assign("previewMailTxt", $previewMailTxt);
$smarty->assign("previewMail", $previewMail);
$smarty->assign("id_campaign", $this->id_campaign);
$smarty->assign("preview", 'true');
} else {
if ($_POST['tmsubmit'] && $_POST["tmsubmit"] === "Test Mail") {
$previewMail = $smarty->fetch(_PS_THEME_DIR_ . $this->template);
$previewMailTxt = $smarty->fetch(_PS_THEME_DIR_ . 'text_' . $this->template);
$smarty->assign("previewMailTxt", $previewMailTxt);
$smarty->assign("previewMail", $previewMail);
$testmail = Tools::getValue('testmail');
if (empty($this->id_campaign) || empty($testmail)) {
$this->_errors[] = "Unable to send test mail. Please check again";
} else {
$templateVars = array();
$templateVars['{mail_content}'] = $previewMail;
$templateVars['{mail_content_text}'] = $previewMailTxt;
@Mail::Send(1, 'mailer_campaign', $this->subject, $templateVars, $testmail, null, 'care@indusdiva.com', 'Indusdiva.com', NULL, NULL, _PS_MAIL_DIR_, false);
$this->_errors[] = "Mail Sent to {$testmail}";
}
$smarty->assign("id_campaign", $this->id_campaign);
$smarty->assign("preview", 'true');
} else {
if ($_POST['ssubmit'] && $_POST["ssubmit"] === "Submit") {
$previewMail = $smarty->fetch(_PS_THEME_DIR_ . $this->template);
$previewMailTxt = $smarty->fetch(_PS_THEME_DIR_ . 'text_' . $this->template);
$smarty->assign("previewMailTxt", $previewMailTxt);
$smarty->assign("previewMail", $previewMail);
$smarty->assign("preview", 'true');
if ($this->id_campaign === 0) {
$this->_errors[] = "Unable to schedule mailer.";
$smarty->assign("id_campaign", $this->id_campaign);
} else {
$scheduled_at = Tools::getValue("scheduled_at");
//convert from local time to UTC
$scheduled_at_gmt = new Datetime($scheduled_at);
$scheduled_at_gmt->setTimezone(new DateTimeZone('GMT'));
$scheduled_at_gmt = $scheduled_at_gmt->format('Y-m-d H:i:s');
$sql = "update ps_mailers set status=1,scheduled_time = '{$scheduled_at_gmt}' where id_campaign = " . $this->id_campaign;
$db->Execute($sql);
$this->_errors[] = "Mail scheduled at {$scheduled_at}";
$smarty->assign("id_campaign", $this->id_campaign);
$this->mailer_confirm = true;
}
}
}
}
$smarty->assign('currentIndex', $currentIndex);
$smarty->assign('token', $this->token);
}
示例5: getDatetime
/**
* DateTimeHelper::getDatetime() from SonataIntlBundle
*
* @param \Datetime|\DateTimeImmutable|string|integer $data
* @param \DateTimeZone timezone
* @return \Datetime
*/
protected function getDatetime($data, \DateTimeZone $timezone)
{
if ($data instanceof \DateTime || $data instanceof \DateTimeImmutable) {
return $data->setTimezone($timezone);
}
// the format method accept array or integer
if (is_numeric($data)) {
$data = (int) $data;
}
if (is_string($data)) {
$data = strtotime($data);
}
// MongoDB Date and Timestamp
if ($data instanceof \MongoDate || $data instanceof \MongoTimestamp) {
$data = $data->sec;
}
// Mongodb bug ? timestamp value is on the key 'i' instead of the key 't'
if (is_array($data) && array_keys($data) == array('t', 'i')) {
$data = $data['i'];
}
$date = new \DateTime();
$date->setTimestamp($data);
$date->setTimezone($timezone);
return $date;
}
示例6: applyICalendarTimes
private function applyICalendarTimes($start, $end, $timezoneID = null)
{
$utc = new DateTimezone('UTC');
$timezone = null;
$userTimeZone = Phprojekt_User_User::getUserDateTimeZone();
if ('Z' === substr($start, -1)) {
$timezone = $utc;
} else {
if (!is_null($timezoneID)) {
$timezone = new DateTimeZone($timezoneID);
} else {
$timezone = $userTimeZone;
}
}
// We can't use ->setTimezone with the timezones returned by getUserDateTimeZone, as these are non-standard
// timezones. Unless we start storing correct timezones, we can't directly set the user timezone, so we go to
// UTC and convert to usertime from there. Because utcToUser returns a unix timestamp, but ActiveRecords expects
// a "Y-m-d H:i:s" timestamp, we have to go through Datetime again.
$start = new Datetime($start, $timezone);
$start->setTimezone($utc);
$startTs = Phprojekt_Converter_Time::utcToUser($start->format('Y-m-d H:i:s'));
$start = new Datetime('@' . $startTs);
$end = new Datetime($end, $timezone);
$end->setTimezone($utc);
$endTs = Phprojekt_Converter_Time::utcToUser($end->format('Y-m-d H:i:s'));
$end = new Datetime('@' . $endTs);
if ($start->diff($end)->invert) {
throw new Sabre_DAV_Exception_BadRequest('Start must be before End');
}
$this->_timecard->startDatetime = $start->format('Y-m-d H:i:s');
if ($start->format('z') == $end->format('z')) {
// Same day
$this->_timecard->endTime = $end->format('H:i:s');
} else {
$this->_timecard->endTime = '23:59:00';
}
}
示例7: getTimeZoneTime
function getTimeZoneTime($timeZone, $time = '')
{
$current_time = new Datetime($time);
$ny_time = new DateTimeZone($timeZone);
$current_time->setTimezone($ny_time);
$current_time = new DateTime($current_time->format("Y-m-d H:i:s"));
return $current_time;
}
示例8: _periodToArray
/**
* Retrieves all events from an dateperiod that lie between two points in time.
*
* This takes event duration in account.
*/
private function _periodToArray(DatePeriod $period, $startTs, $endTs)
{
$ret = array();
foreach ($period as $date) {
// Work around http://bugs.php.net/bug.php?id=52454
// 'Relative dates and getTimestamp increments by one day'
$datestring = $date->format('Y-m-d H:i:s');
$date = new Datetime($datestring, new DateTimeZone('UTC'));
$ts = $date->getTimestamp();
if ($startTs <= $ts + $this->_duration && $ts <= $endTs && !in_array($date, $this->_exceptions)) {
$dt = new Datetime('@' . $ts);
$dt->setTimezone(new DateTimeZone('utc'));
$ret[] = $dt;
} else {
if ($ts > $endTs) {
break;
}
}
}
return $ret;
}
示例9: getRandomBirthday
public function getRandomBirthday()
{
$min_unix_date_obj = new DateTime("1900-01-01 00:00:00");
$min_unix_date_obj->setTimezone(new DateTimeZone("PRC"));
$min_unix_date = $min_unix_date_obj->format("U");
$max_unix_date = time();
$random_date_unix = mt_rand($min_unix_date, $max_unix_date);
$random_date_obj = new Datetime("@{$random_date_unix}");
$random_date_obj->setTimezone(new DateTimeZone("PRC"));
$random_date = $random_date_obj->format("Ymd");
return $random_date;
}