本文整理汇总了PHP中Carbon\Carbon::getTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::getTimestamp方法的具体用法?PHP Carbon::getTimestamp怎么用?PHP Carbon::getTimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::getTimestamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFilters
/**
* Dodatkowe filtry Twig zwiazane z formatowaniem danych uzytkownika
*
* @return array
*/
public function getFilters()
{
return [new Twig_SimpleFilter('format_date', function ($dateTime, $diffForHumans = true) {
$format = Auth::check() ? auth()->user()->date_format : '%Y-%m-%d %H:%M';
if (!$dateTime instanceof Carbon) {
$dateTime = new Carbon($dateTime);
}
$now = Carbon::now();
if (!$diffForHumans) {
return $dateTime->formatLocalized($format);
} elseif ($dateTime->diffInHours($now) < 1) {
return $dateTime->diffForHumans(null, true) . ' temu';
} elseif ($dateTime->isToday()) {
return 'dziś, ' . $dateTime->format('H:i');
} elseif ($dateTime->isYesterday()) {
return 'wczoraj, ' . $dateTime->format('H:i');
} else {
return $dateTime->formatLocalized($format);
}
}), new Twig_SimpleFilter('timestamp', function ($dateTime) {
if ($dateTime instanceof Carbon) {
return $dateTime->getTimestamp();
} else {
return strtotime($dateTime);
}
})];
}
示例2: getTrialEndForUpdate
/**
* Get the trial end timestamp for a Stripe subscription update.
*
* @return int
*/
protected function getTrialEndForUpdate()
{
if ($this->skipTrial) {
return 'now';
}
return $this->trialEnd ? $this->trialEnd->getTimestamp() : null;
}
示例3: diffInDates
public static function diffInDates(Carbon $date1, Carbon $date2)
{
$date1ToSeconds = $date1->getTimestamp();
$date2ToSeconds = $date2->getTimestamp();
$difference = $date1ToSeconds - $date2ToSeconds;
return self::differenceToTime($difference);
}
示例4: extract
/**
* {@inheritdoc}
*
* @return int
*/
public function extract($model)
{
$value = parent::extract($model);
if ($value === null) {
return null;
}
if (!$value instanceof Carbon) {
$value = new Carbon($value);
}
return $value->getTimestamp();
}
示例5: registerMarkupTags
/**
* Registers CMS markup tags introduced by this plugin.
*
* @return array
*/
public function registerMarkupTags()
{
return ['filters' => ['strftime' => function ($time, $format) {
static $locale;
if (!$locale) {
$locale = Lang::getLocale();
Carbon::setLocale($locale);
setlocale(LC_TIME, sprintf('%s_%s.UTF-8', $locale, strtoupper($locale)));
}
if (!$time instanceof Carbon) {
$time = new Carbon($time);
}
return strftime($format, $time->getTimestamp());
}]];
}
示例6: getMtime
/**
*
* Returns last post's published_at timestamp for current year
* or $year/12/31 00:00:00 timestamp for other years
*
* @param $year
* @return int
*/
protected static function getMtime($year)
{
if ($year == date('Y')) {
$post = BlogPost::orderBy('published_at', 'desc')->isPublished()->first();
if ($post) {
$date = new Carbon($post->published_at);
} else {
// if no posts, set date to the first of january
$date = new Carbon();
$date->setDateTime(date('Y'), 1, 1, 0, 0, 0);
}
} else {
// previous year
$date = new Carbon();
$date->setDateTime($year, 12, 31, 0, 0, 0);
}
return $date->getTimestamp();
}
示例7: serialize
/**
* Serialize SharePoint Access Token
*
* @access public
* @return string
*/
public function serialize()
{
return serialize([$this->token, $this->expires->getTimestamp(), $this->expires->getTimezone()->getName()]);
}
示例8: registerMarkupTags
/**
* Add Twig extensions
*
* @see Text extensions http://twig.sensiolabs.org/doc/extensions/text.html
* @see Intl extensions http://twig.sensiolabs.org/doc/extensions/intl.html
* @see Array extension http://twig.sensiolabs.org/doc/extensions/array.html
* @see Time extension http://twig.sensiolabs.org/doc/extensions/date.html
*
* @return array
*/
public function registerMarkupTags()
{
$twig = App::make('twig.environment');
$filters = [];
// add Text extensions
$textExtension = new \Twig_Extensions_Extension_Text();
$textFilters = $textExtension->getFilters();
$filters += ['truncate' => function ($value, $length = 30, $preserve = false, $separator = '...') use($twig, $textFilters) {
$callable = $textFilters['0']->getCallable();
return $callable($twig, $value, $length, $preserve, $separator);
}, 'wordwrap' => function ($value, $length = 80, $separator = "\n", $preserve = false) use($twig, $textFilters) {
$callable = $textFilters['1']->getCallable();
return $callable($twig, $value, $length, $separator, $preserve);
}];
// add Intl extensions if php5-intl installed
if (class_exists('IntlDateFormatter')) {
$intlExtension = new \Twig_Extensions_Extension_Intl();
$intlFilters = $intlExtension->getFilters();
$filters += ['localizeddate' => function ($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null, $format = null) use($twig, $intlFilters) {
$callable = $intlFilters['0']->getCallable();
return $callable($twig, $date, $dateFormat, $timeFormat, $locale, $timezone, $format);
}, 'localizednumber' => function ($number, $style = 'decimal', $type = 'default', $locale = null) use($twig, $intlFilters) {
$callable = $intlFilters['1']->getCallable();
return $callable($twig, $number, $style, $type, $locale);
}, 'localizedcurrency' => function ($number, $currency = null, $locale = null) use($twig, $intlFilters) {
$callable = $intlFilters['2']->getCallable();
return $callable($twig, $number, $currency, $locale);
}];
}
// add Array extensions
$arrayExtension = new \Twig_Extensions_Extension_Array();
$arrayFilters = $arrayExtension->getFilters();
$filters += ['shuffle' => function ($array) use($twig, $arrayFilters) {
$callable = $arrayFilters['0']->getCallable();
return $callable($twig, $array);
}];
// add Time extensions
$timeExtension = new \Twig_Extensions_Extension_Date();
$timeFilters = $timeExtension->getFilters();
$filters += ['time_diff' => function ($date, $now = null) use($twig, $timeFilters) {
$callable = $timeFilters['0']->getCallable();
return $callable($twig, $date, $now);
}];
// add PHP functions
$filters += ['strftime' => function ($time, $format = '%d.%m.%Y %H:%M:%S') {
$timeObj = new Carbon($time);
return strftime($format, $timeObj->getTimestamp());
}, 'uppercase' => function ($string) {
return strtoupper($string);
}, 'lowercase' => function ($string) {
return strtolower($string);
}, 'ucfirst' => function ($string) {
return ucfirst($string);
}, 'lcfirst' => function ($string) {
return lcfirst($string);
}, 'ltrim' => function ($string, $charlist = " \t\n\r\v") {
return ltrim($string, $charlist);
}, 'rtrim' => function ($string, $charlist = " \t\n\r\v") {
return rtrim($string, $charlist);
}, 'str_repeat' => function ($string, $multiplier = 1) {
return str_repeat($string, $multiplier);
}, 'plural' => function ($string, $count = 2) {
return str_plural($string, $count);
}];
return ['filters' => $filters];
}
示例9: isInRange
/**
*
* Checks if current date in in range of ($first_date:time())
*
* @return bool
*/
protected function isInRange()
{
$first_date = self::getFirstDate();
if (!$this->month) {
$first_date->month(1);
}
if (!$this->day) {
$first_date->day(1);
}
$now = new Carbon();
$year = $this->year;
$month = !$this->month ? '1' : $this->month;
$day = !$this->day ? '1' : $this->day;
$current = new Carbon();
$current->setDate($year, $month, $day);
$current->setTime(0, 0);
return $first_date->getTimestamp() <= $current->getTimestamp() && $current->getTimestamp() <= $now->getTimestamp();
}
示例10: fullmix
public function fullmix($dateType, $timeType, Carbon $carbon)
{
$fmt = new IntlDateFormatter($this->langCode, $this->getType($dateType), $this->getType($timeType), $carbon->tz);
return $fmt->format($carbon->getTimestamp());
}
示例11: formatDate
protected function formatDate(Carbon $date)
{
return ['rfc3339' => $date->toRfc3339String(), 'timestamp' => $date->getTimestamp(), 'diffForHumans' => $date->diffForHumans()];
}
示例12: postPause
public function postPause($stream)
{
$time = Input::get('time');
$date = new Carbon($time);
$series = AnnouncementSeries::find($stream);
$series->paused_until = $date;
$series->save();
$this->broadcast(array('stream' => $series, 'type' => 'pause', 'date' => $date->getTimestamp()));
}
示例13: timestamp
/**
* Set the timestamp.
*
* @param Carbon $timestamp
* @return $this
*/
public function timestamp(Carbon $timestamp)
{
$this->timestamp = $timestamp->getTimestamp();
return $this;
}
示例14: getReadableSort
/**
* {@inheritDoc}
*/
public function getReadableSort()
{
return $this->date->getTimestamp();
}
示例15: setupDayPager
/**
* Sets up pager to switch prev/next day
*/
protected function setupDayPager()
{
$first_date = $this->first_date;
$current_date = $this->current_date;
// previous
if ($first_date->getTimestamp() < $current_date->getTimestamp()) {
$previous_date = $current_date->copy();
$previous_date->subDay(1);
$this->previous_text = $previous_date->formatLocalized('%d') . ' ' . $previous_date->formatLocalized('%B') . ', ' . $previous_date->year;
$this->previous_url = $this->makePagerUrl(array('year' => $previous_date->year, 'month' => $previous_date->month, 'day' => $previous_date->day));
} else {
$this->previous_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
$this->previous_url = '';
}
// next
$today = new Carbon();
$today->setTime(0, 0);
if ($this->current_date->getTimestamp() < $today->getTimestamp()) {
$next_date = $current_date->copy();
$next_date->addDay(1);
$this->next_text = $next_date->formatLocalized('%d') . ' ' . $next_date->formatLocalized('%B') . ', ' . $next_date->year;
$this->next_url = $this->makePagerUrl(array('year' => $next_date->year, 'month' => $next_date->month, 'day' => $next_date->day));
} else {
$this->next_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
$this->next_url = '';
}
}