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


PHP Date::createFromFormat方法代码示例

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


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

示例1: handle

 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
     // Link with the component.
     if ($command->component_id) {
         $data['component_id'] = $command->component_id;
     }
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $data['created_at'] = $incidentDate;
         $data['updated_at'] = $incidentDate;
     }
     // Create the incident
     $incident = Incident::create($data);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     if ($command->notify) {
         event(new IncidentWasReportedEvent($incident));
     }
     return $incident;
 }
开发者ID:ryanwinchester-forks,项目名称:Cachet,代码行数:32,代码来源:ReportIncidentCommandHandler.php

示例2: getInsert

 public function getInsert()
 {
     //if(Input::old('tanggal')!="" and Input::old('nis')!="") {
     $siswa = \DB::table('t_siswa_tingkat')->where('nis', Input::old('nis'))->first();
     if ($siswa == null) {
         \Session::flash('siswa_ilang', 'NIS tidak ditemukan');
         return redirect('/home');
     }
     $date = Date::createFromFormat('Y-m-d', Input::old('tanggal'));
     $tapel = AbsencesController::checkPeriode($date);
     $tapel['kd_tapel'] = \DB::table('t_tahun_ajaran')->where('tahun_ajaran', $tapel['tahun_ajaran'])->first()->kd_tahun_ajaran;
     $siswa_tingkat = \DB::table('t_siswa_tingkat')->where('nis', $siswa->nis)->where('kd_tahun_ajaran', $tapel['kd_tapel'])->where('kd_periode_belajar', $tapel['periode'])->first();
     if ($siswa_tingkat == null) {
         \Session::flash('tahun_ajaran', 'Tahun ajaran belum dimulai');
         return redirect('/home');
     }
     $siswa = \DB::table('t_siswa')->where('nis', $siswa->nis)->first();
     $pikets = \DB::table('t_piket')->where('hari', $date->format('l'))->first();
     $piket = \DB::table('t_guru')->where('kd_guru', $pikets->kd_guru)->first();
     $jam_masuk = Date::createFromFormat('H:i:s', $pikets->jam_masuk, Date::now()->tzName);
     return view('absences.insert', compact('date', 'jam_masuk', 'siswa', 'siswa_tingkat', 'piket', 'tapel'));
     //}
     //else
     //    return redirect('home');
 }
开发者ID:rizkidoank,项目名称:smansa-absensi,代码行数:25,代码来源:AbsencesController.php

示例3: handle

 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     // Notify subscribers.
     event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     return $maintenanceEvent;
 }
开发者ID:ryanwinchester-forks,项目名称:Cachet,代码行数:15,代码来源:ReportMaintenanceCommandHandler.php

示例4: handle

 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     // TODO: Add validation to scheduledAt
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     // Notify subscribers.
     if ($command->notify) {
         event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     }
     return $maintenanceEvent;
 }
开发者ID:practico,项目名称:Cachet,代码行数:18,代码来源:ReportMaintenanceCommandHandler.php

示例5: asDateTime

 protected function asDateTime($value)
 {
     if (is_numeric($value)) {
         return Date::createFromTimestamp($value);
     } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
         return Date::createFromFormat('Y-m-d', $value)->startOfDay();
     } elseif (!$value instanceof DateTime) {
         $format = $this->getDateFormat();
         return Date::createFromFormat($format, $value);
     }
     return Date::instance($value);
 }
开发者ID:ankhzet,项目名称:Ankh,代码行数:12,代码来源:DateAccessorTrait.php

示例6: showIndex

 /**
  * Returns the rendered Blade templates.
  *
  * @return \Illuminate\View\View
  */
 public function showIndex()
 {
     $today = Date::now();
     $startDate = Date::now();
     segment_page('Status Page');
     // Check if we have another starting date
     if (Binput::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
             segment_track('Status Page', ['start_date' => $oldDate->format('Y-m-d')]);
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $metrics = null;
     if ($displayMetrics = Setting::get('display_graphs')) {
         $metrics = Metric::where('display_chart', 1)->get();
     }
     $daysToShow = Setting::get('app_incident_days') ?: 7;
     $incidentDays = range(0, $daysToShow - 1);
     $dateTimeZone = Setting::get('app_timezone');
     $incidentVisiblity = Auth::check() ? 0 : 1;
     $allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisiblity)->whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use($dateTimeZone) {
         return (new Date($incident->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no incidents
     foreach ($incidentDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIncidents[$date->toDateString()])) {
             $allIncidents[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIncidents = $allIncidents->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     // Scheduled maintenance code.
     $scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
     // Component & Component Group lists.
     $usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
     $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
     $ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
     $canPageBackward = Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() != 0;
     return View::make('index', ['componentGroups' => $componentGroups, 'ungroupedComponents' => $ungroupedComponents, 'displayMetrics' => $displayMetrics, 'metrics' => $metrics, 'allIncidents' => $allIncidents, 'scheduledMaintenance' => $scheduledMaintenance, 'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')), 'canPageForward' => (bool) $today->gt($startDate), 'canPageBackward' => $canPageBackward, 'previousDate' => $startDate->copy()->subDays($daysToShow)->toDateString(), 'nextDate' => $startDate->copy()->addDays($daysToShow)->toDateString(), 'pageTitle' => Setting::get('app_name') . ' Status']);
 }
开发者ID:2bj,项目名称:Cachet,代码行数:55,代码来源:HomeController.php

示例7: asDateTime

 /**
  * Return a timestamp as DateTime object.
  *
  * @param  mixed  $value
  * @return \Jenssegers\Date\Date
  */
 protected function asDateTime($value)
 {
     // If this value is an integer, we will assume it is a UNIX timestamp's value
     // and format a Carbon object from this timestamp. This allows flexibility
     // when defining your date fields as they might be UNIX timestamps here.
     if (is_numeric($value)) {
         return Date::createFromTimestamp($value);
     } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
         return Date::createFromFormat('Y-m-d', $value)->startOfDay();
     } elseif (!$value instanceof DateTime) {
         $format = $this->getDateFormat();
         return Date::createFromFormat($format, $value);
     }
     return Date::instance($value);
 }
开发者ID:qwildz,项目名称:localized-eloquent-date,代码行数:21,代码来源:LocalizedDateTrait.php

示例8: showIndex

 /**
  * Displays the explore page.
  *
  * @return \Illuminate\View\View
  */
 public function showIndex()
 {
     $today = Date::now();
     $startDate = Date::now();
     // Check if we have another starting date
     if (Binput::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $daysToShow = Setting::get('app_issue_days', 0) - 1;
     if ($daysToShow < 0) {
         $daysToShow = 0;
         $issueDays = [];
     } else {
         $issueDays = range(0, $daysToShow);
     }
     $dateTimeZone = Setting::get('app_timezone');
     $issueVisiblity = Auth::check() ? 0 : 1;
     $allIssues = Issue::where('visible', '>=', $issueVisiblity)->whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->groupBy(function (Issue $issue) use($dateTimeZone) {
         // If it's scheduled, get the scheduled at date.
         if ($issue->is_scheduled) {
             return (new Date($issue->scheduled_at))->setTimezone($dateTimeZone)->toDateString();
         }
         return (new Date($issue->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no issues
     foreach ($issueDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIssues[$date->toDateString()])) {
             $allIssues[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIssues = $allIssues->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     return View::make('index')->withDaysToShow($daysToShow)->withAllIssues($allIssues)->withCanPageForward((bool) $today->gt($startDate))->withCanPageBackward(Issue::where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString());
 }
开发者ID:emtudo,项目名称:Gitamin,代码行数:51,代码来源:ExploreController.php

示例9: handle

 /**
  * Handle the update incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(UpdateIncidentCommand $command)
 {
     $incident = $command->incident;
     $incident->update($this->filterIncidentData($command));
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $incident->update(['created_at' => $incidentDate, 'updated_at' => $incidentDate]);
     }
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     event(new IncidentWasUpdatedEvent($incident));
     return $incident;
 }
开发者ID:ryanwinchester-forks,项目名称:Cachet,代码行数:24,代码来源:UpdateIncidentCommandHandler.php

示例10: asDateTime

 /**
  * Return a timestamp as DateTime object.
  *
  * @param  mixed  $value
  * @return \Carbon\Carbon
  */
 protected function asDateTime($value)
 {
     Date::setLocale('it');
     // If the value is already a DateTime instance, we will just skip the rest of
     // these checks since they will be a waste of time, and hinder performance
     // when checking the field. We will just return the DateTime right away.
     if ($value instanceof DateTime) {
         //
     } elseif (is_numeric($value)) {
         return Date::createFromTimestamp($value);
     } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
         return Date::createFromFormat('Y-m-d', $value)->startOfDay();
     } elseif (!$value instanceof DateTime) {
         $format = $this->getDateFormat();
         return Date::createFromFormat($format, $value);
     }
     return Date::instance($value);
 }
开发者ID:AssociazionePrometeo,项目名称:doorkeeper-web,代码行数:24,代码来源:LocalizesDates.php

示例11: indexAction

 /**
  * Displays the explore page.
  *
  * @return \Illuminate\View\View
  */
 public function indexAction()
 {
     $this->subMenu['explore']['active'] = true;
     $today = Date::now();
     $startDate = Date::now();
     // Check if we have another starting date
     if (Request::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Request::get('start_date'));
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $daysToShow = Setting::get('app_issue_days', 0) - 1;
     if ($daysToShow < 0) {
         $daysToShow = 0;
         $issueDays = [];
     } else {
         $issueDays = range(0, $daysToShow);
     }
     $dateTimeZone = Setting::get('app_timezone');
     $allIssues = Issue::whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get()->groupBy(function (Issue $issue) use($dateTimeZone) {
         return (new Date($issue->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no issues
     foreach ($issueDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIssues[$date->toDateString()])) {
             $allIssues[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIssues = $allIssues->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     return View::make('explore.index')->withPageTitle(trans('dashboard.explore'))->withProjects([])->withSubMenu($this->subMenu)->withDaysToShow($daysToShow)->withAllIssues($allIssues)->withCanPageForward((bool) $today->gt($startDate))->withCanPageBackward(Issue::where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString());
 }
开发者ID:xiaobailc,项目名称:Gitamin,代码行数:47,代码来源:ExploreController.php

示例12: handleTypeConversions

 /**
  * Handle various type conversions that should be supported natively by Doctrine (like DateTime)
  *
  * @param  mixed $value
  * @param  string $typeOfField
  * @return Date
  */
 protected function handleTypeConversions($value, $typeOfField)
 {
     switch ($typeOfField) {
         case 'datetimetz':
         case 'datetime':
         case 'time':
         case 'date':
             if ('' === $value) {
                 return null;
             }
             if (is_int($value)) {
                 $value = Date::createFromTimestamp($value);
             } elseif (is_string($value)) {
                 $value = Date::createFromFormat('d/M/Y', $value);
             }
             break;
         default:
     }
     return $value;
 }
开发者ID:zetta-code,项目名称:tss-doctrineutil,代码行数:27,代码来源:DoctrineObject.php

示例13: hdate

 function hdate($date)
 {
     $obj = \Jenssegers\Date\Date::createFromFormat('Y-m-d H:i:s', $date);
     return $obj->ago();
 }
开发者ID:vitos8686,项目名称:0ez,代码行数:5,代码来源:helpers.php

示例14: editScheduleAction

 /**
  * Updates the given incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident $schedule
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editScheduleAction(Incident $schedule)
 {
     $scheduleData = Binput::get('incident');
     // Parse the schedule date.
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
     if ($scheduledAt->isPast()) {
         $messageBag = new MessageBag();
         $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
         return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withErrors($messageBag);
     }
     $scheduleData['scheduled_at'] = $scheduledAt;
     // Bypass the incident.status field.
     $scheduleData['status'] = 0;
     try {
         $schedule->update($scheduleData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->withErrors($e->getMessageBag());
     }
     return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success')));
 }
开发者ID:ramirors,项目名称:Cachet,代码行数:27,代码来源:ScheduleController.php

示例15: editScheduleAction

 /**
  * Updates the given incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident $schedule
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editScheduleAction(Incident $schedule)
 {
     $scheduleData = Binput::get('incident');
     // Parse the schedule date.
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
     if ($scheduledAt->isPast()) {
         $messageBag = new MessageBag();
         $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
         return Redirect::back()->withErrors($messageBag);
     }
     $scheduleData['scheduled_at'] = $scheduledAt;
     // Bypass the incident.status field.
     $scheduleData['status'] = 0;
     $schedule->update($scheduleData);
     if (!$schedule->isValid()) {
         segment_track('Dashboard', ['event' => 'Edited Schedule', 'success' => false]);
         return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->with('errors', $schedule->getErrors());
     }
     segment_track('Dashboard', ['event' => 'Edited Schedule', 'success' => true]);
     $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success'));
     return Redirect::to('dashboard/schedule')->with('success', $successMsg);
 }
开发者ID:hd-deman,项目名称:Cachet,代码行数:29,代码来源:ScheduleController.php


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