本文整理匯總了PHP中DateInterval::createfromdatestring方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateInterval::createfromdatestring方法的具體用法?PHP DateInterval::createfromdatestring怎麽用?PHP DateInterval::createfromdatestring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DateInterval
的用法示例。
在下文中一共展示了DateInterval::createfromdatestring方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: tracks_get
/**
* @author Julie Engel <entwicklung@metanet.ch>
* @copyright Copyright (c) 2015, METANET AG
*/
function tracks_get(DateTime $date)
{
$previous_day = clone $date;
$previous_day = $previous_day->sub(DateInterval::createfromdatestring('+1 day'));
$next_day = clone $date;
$next_day = $next_day->sub(DateInterval::createfromdatestring('-1 day'));
//var_dump("-----------------------");
//var_dump($date);
//var_dump($previous_day);
//var_dump($next_day);
$LASTFM_API_URL = 'http://ws.audioscrobbler.com/2.0/';
$LASTFM_API_METHOD = 'user.getrecenttracks';
$LASTFM_API_KEY = 'your_api_key';
$LASTFM_USER = 'your_username';
$params = array('method' => $LASTFM_API_METHOD, 'user' => $LASTFM_USER, 'api_key' => $LASTFM_API_KEY, 'from' => $previous_day->getTimestamp(), 'to' => $next_day->getTimestamp(), 'format' => 'json');
$query = http_build_query($params);
$call = $LASTFM_API_URL . '?' . $query;
$curl = curl_init($call);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
} else {
//echo 'response ok!';
}
//var_dump($decoded);
if (isset($decoded->recenttracks->track)) {
$tracks = $decoded->recenttracks->track;
if (is_array($tracks)) {
$tracks = array_reverse($tracks);
} else {
$track_item = $tracks;
$tracks = array($track_item);
}
return $tracks;
} else {
return null;
}
}
示例2: blendercloud_api
//.........這裏部分代碼省略.........
$tmp['cloud_access'] = 1;
}
if ($expiry_date > $last_expiration_date) {
$last_expiration_date = $expiry_date;
}
$user_data['subscriptions'][] = $tmp;
}
}
// process recurring subscriptions
$subscriptions = WC_Subscriptions_Manager::get_users_subscriptions($user_id);
if (!empty($subscriptions)) {
// iterate over all subscriptions.
foreach ($subscriptions as $subscription_details) {
if ($subscription_details['status'] != 'trash') {
$order_id = $subscription_details['order_id'];
$product_id = $subscription_details['product_id'];
$order = new WC_Order($order_id);
// print_r($order);
// $next_payment_date = WC_Subscriptions_Manager::get_next_payment_date( $subscription_key, $user_id, 'mysql' );
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($order_id, $product_id);
if ($subscription_details['expiry_date'] == 0 && !in_array($subscription_details['status'], array('cancelled', 'switched'))) {
$end_time = WC_Subscriptions_Manager::get_next_payment_date($subscription_key, $user_id, 'mysql');
$end_timestamp = strtotime($end_time);
} else {
if (in_array($subscription_details['status'], array('cancelled', 'switched'))) {
$end_of_prepaid_term = wc_next_scheduled_action('scheduled_subscription_end_of_prepaid_term', array('user_id' => (int) $user_id, 'subscription_key' => $subscription_key));
if (false === $end_of_prepaid_term) {
$end_timestamp = strtotime($subscription_details['end_date']);
} else {
$end_timestamp = $end_of_prepaid_term;
}
} else {
$end_timestamp = strtotime($subscription_details['expiry_date']);
}
}
// if( $users[0]->data->user_email == 'perepausancho@gmail.com' ) {
// print_r($subscription_details);
// }
if ($subscription_details['status'] == 'cancelled') {
$end_timestamp = strtotime($subscription_details['trial_expiry_date']);
}
if ($subscription_details['status'] == 'on-hold') {
$end_timestamp = strtotime($subscription_details['last_payment_date']);
}
$end_time = date("Y-m-d H:i:s", $end_timestamp);
$product = get_product($product_id);
$sku = $product->get_sku();
$tmp = bo_empty_subscription_line();
$tmp['expiration_date'] = $end_time;
$tmp['subscription_status'] = $subscription_details['status'];
$expiry_date = new DateTime($end_time);
if ($expiry_date > $last_expiration_date) {
$last_expiration_date = $expiry_date;
}
$now = new DateTime("now");
$tmp['cloud_access'] = $expiry_date > $now ? 1 : 0;
$tmp['sku'] = $sku;
// if order is refunded, stop access
if ($order->status == 'refunded') {
$tmp['expiration_date'] = $end_time;
$tmp['subscription_status'] = 'refunded';
$tmp['cloud_access'] = 0;
}
switch ($sku) {
case 'cloud-subscription-1-renewal':
case 'cloud-subscription-3':
//$tmp['failed_payments'] = $subscription['failed_payments'];
break;
case 'cloud-subscription-team':
// purchased team size
$variation_id = $subscription_details['variation_id'];
// find variation info from order to pass on # of seats
$order = new WC_Order($order_id);
$items = $order->get_items();
$team_members = 0;
foreach ($items as $item) {
// does product variation id match the current subscription?
if ($item['item_meta']['_variation_id'][0] == $variation_id) {
$team_members = $item['item_meta']['pa_team-size'][0];
}
}
$tmp['team_members'] = $team_members;
break;
}
$user_data['subscriptions'][] = $tmp;
}
}
}
}
// add one grace day to expiration
$last_expiration_date->add(DateInterval::createfromdatestring('+1 day'));
$user_data['expiration_date'] = $last_expiration_date->format('Y-m-d H:i:s');
$now = new DateTime("now");
if ($last_expiration_date > $now) {
$user_data['cloud_access'] = 1;
}
//echo "<pre>";print_r($user_data);
echo json_encode($user_data, JSON_PRETTY_PRINT);
die;
}
示例3: date
$pdate = $row['pdate'];
$arrFin[$pdate] = $row['num'];
$log->logInfo("Fin pDate:" % $pdate);
}
$tableName = "six_matches_status";
$dateField = "updated";
$sql = "SELECT date( " . $dateField . " ) AS pdate, COUNT( id ) AS num\n FROM " . $tableName . " \n WHERE " . $dateField . " > date_sub( date( now( ) ) , INTERVAL " . $days . " DAY )\n AND " . $dateField . " < CURRENT_DATE()\n GROUP BY pdate\n ORDER BY pdate ASC";
$result = mysql_query($sql);
$log->logInfo($sql);
$arrUnfin = array();
while ($row = mysql_fetch_array($result)) {
$arrUnfin[$row['pdate']] = $row['num'];
}
$startDate = new DateTime();
$startDate->add(DateInterval::createfromdatestring('-' . $days . ' day'));
$day = DateInterval::createfromdatestring('+1 day');
while ($startDate->getTimestamp() < time()) {
$dateStr = $startDate->format('Y-m-d');
$startDate = $startDate->add($day);
if (array_key_exists($dateStr, $arrFin)) {
$pts = $arrFin[$dateStr];
$myData->AddPoints($pts, "Finished");
} else {
$myData->AddPoints(VOID, "Finished");
}
if (array_key_exists($dateStr, $arrUnfin)) {
$pts = $arrUnfin[$dateStr];
$myData->AddPoints($pts, "Unfinished");
} else {
$myData->AddPoints(VOID, "Unfinished");
}
示例4: Add
public function Add()
{
if ($this->user->IsUserLogger() == false) {
$this->routemanager->RedirectToAction('index', 'home');
}
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
//если все данные введены корректно
if ($this->ValidateAddForm()) {
//подключаем модель и регестрируем пользователя\
$this->loader->model("taskRepository");
$this->model_taskRepository->AddTask($this->user->GetUserId(), $this->request->post);
$this->routemanager->RedirectToAction('index', 'task', array("msg" => "as"));
}
$this->data["name"] = $this->request->post["name"];
$this->data["description"] = $this->request->post["description"];
$this->data["start"] = $this->request->post["start"];
$this->data["end"] = $this->request->post["end"];
$this->data["email_notify"] = $this->request->post["email_notify"];
$this->data["phone_notify"] = $this->request->post["phone_notify"];
} else {
//инициализация дат (ближайщий час)
$format = 'd.m.Y H';
$data = new DateTime();
$data->add(DateInterval::createfromdatestring('+1 hour'));
$this->data["start"] = $data->format($format) . '.00';
$data->add(DateInterval::createfromdatestring('+1 hour'));
$this->data["end"] = $data->format($format) . '.00';
}
$this->data["title"] = "Добавить задачу";
$this->text["name"] = "Название задачи";
$this->text["description"] = "Описание задачи";
$this->text["start"] = "Начало";
$this->text["end"] = "Конец";
$this->text["email_notify"] = "Уведомить на email";
$this->text["phone_notify"] = "Уведомить на телефон";
$this->View();
}
示例5: header
<?php
//Datumsspanne
if (isset($_GET['startDate']) && isset($_GET['endDate'])) {
$startDate = DateTime::createFromFormat('d.m.Y', $_GET['startDate']);
$endDate = DateTime::createFromFormat('d.m.Y', $_GET['endDate']);
if ($startDate === false || $endDate === false) {
$_SESSION['message'] = ['type' => 'danger', 'text' => 'Datum in Format d.m.Y'];
//Seite neu laden --> falsches Format
header('location: ' . LINK_MONEY);
}
} else {
$endDate = new DateTime();
$startDate = new DateTime();
//enddatum --> 6Monate zurück
$interv = DateInterval::createfromdatestring('-6 months');
$startDate->add($interv);
}
$acc_histories = $dbmanager->getRange('Account_History', ['payed', 'date_payed'], 'ASC', ['account_id' => $acc->getId()], ['start' => $startDate, 'end' => $endDate]);
?>
<div class="row">
<div class="col-md-1">
<label for="range_start" class="pull-right">Von:</label>
</div>
<div class="col-md-3">
<input type="text" class="form-control input-sm datepicker-range" id="range_start" value="<?php
echo $startDate->format('d.m.Y');
?>
">
</div>