本文整理匯總了PHP中kartik\datecontrol\DateControl::getTimestamp方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateControl::getTimestamp方法的具體用法?PHP DateControl::getTimestamp怎麽用?PHP DateControl::getTimestamp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類kartik\datecontrol\DateControl
的用法示例。
在下文中一共展示了DateControl::getTimestamp方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionConvert
/**
* Convert display date for saving to model
*
* @return string JSON encoded HTML output
*/
public function actionConvert()
{
$output = '';
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$post = Yii::$app->request->post();
if (isset($post['displayDate'])) {
$type = empty($post['type']) ? Module::FORMAT_DATE : $post['type'];
$saveFormat = ArrayHelper::getValue($post, 'saveFormat');
$dispFormat = ArrayHelper::getValue($post, 'dispFormat');
$dispTimezone = ArrayHelper::getValue($post, 'dispTimezone');
$saveTimezone = ArrayHelper::getValue($post, 'saveTimezone');
$settings = ArrayHelper::getValue($post, 'settings', []);
$dispDate = ArrayHelper::getValue($post, 'displayDate');
$date = DateControl::getTimestamp($type, $dispDate, $dispFormat, $dispTimezone, $settings);
if (empty($date) || !$date) {
$value = '';
} elseif ($saveTimezone != null) {
$value = $date->setTimezone(new DateTimeZone($saveTimezone))->format($saveFormat);
} else {
$value = $date->format($saveFormat);
}
return ['status' => 'success', 'output' => $value];
} else {
return ['status' => 'error', 'output' => 'No display date found'];
}
}
示例2: actionConvert
/**
* Convert display date for saving to model
*
* @return string JSON encoded HTML output
*/
public function actionConvert()
{
$output = '';
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$post = Yii::$app->request->post();
if (isset($post['displayDate'])) {
$saveFormat = ArrayHelper::getValue($post, 'saveFormat');
$dispFormat = ArrayHelper::getValue($post, 'dispFormat');
$dispTimezone = ArrayHelper::getValue($post, 'dispTimezone');
$saveTimezone = ArrayHelper::getValue($post, 'saveTimezone');
$settings = ArrayHelper::getValue($post, 'settings', []);
// Russian dates ends with \r. - i dont know why
if (StringHelper::endsWith($dispFormat, '.')) {
$dispFormat = substr($dispFormat, 0, strlen($dispFormat) - 4);
$post['displayDate'] = substr($post['displayDate'], 0, strlen($post['displayDate']) - 4);
}
if (ArrayHelper::getValue($post, 'type') != DateControl::FORMAT_DATETIME) {
$dispTimezone = null;
$saveTimezone = null;
}
$date = DateControl::getTimestamp($post['displayDate'], $dispFormat, $dispTimezone, $settings);
if (empty($date) || !$date) {
$value = '';
} elseif ($saveTimezone != null) {
$value = $date->setTimezone(new DateTimeZone($saveTimezone))->format($saveFormat);
} else {
$value = $date->format($saveFormat);
}
return ['status' => 'success', 'output' => $value];
} else {
return ['status' => 'error', 'output' => 'No display date found'];
}
}
示例3: actionConvert
/**
* Convert display date for saving to model.
*
* @return string JSON encoded HTML output
*/
public function actionConvert()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$post = Yii::$app->request->post();
if (!isset($post['displayDate'])) {
return ['status' => 'error', 'output' => 'No display date found'];
}
$saveFormat = $dispFormat = $dispTimezone = $saveTimezone = $displayDate = '';
$settings = [];
extract($post);
$date = DateControl::getTimestamp($displayDate, $dispFormat, $dispTimezone, $settings);
if (empty($date) || !$date) {
$value = '';
} elseif ($saveTimezone != null) {
$value = $date->setTimezone(new DateTimeZone($saveTimezone))->format($saveFormat);
} else {
$value = $date->format($saveFormat);
}
return ['status' => 'success', 'output' => $value];
}