public static function all() { $timeZones = []; $timeZonesOutput = []; $now = new \DateTime('now', new \DateTimeZone('UTC')); foreach (\DateTimeZone::listIdentifiers(\DateTimeZone::ALL) as $timeZone) { $now->setTimezone(new \DateTimeZone($timeZone)); $timeZones[] = [$now->format('P'), $timeZone]; } if (self::$sortBy == static::SORT_OFFSET) { array_multisort($timeZones); } foreach ($timeZones as $timeZone) { $content = preg_replace_callback("/{\\w+}/", function ($matches) use($timeZone) { switch ($matches[0]) { case '{name}': return $timeZone[1]; case '{offset}': return $timeZone[0]; default: return $matches[0]; } }, self::$template); $timeZonesOutput[$timeZone[1]] = $content; } return $timeZonesOutput; }
public static function since($time, $tz = null, $max_parts = 0) { $f = new \DateTime(date('Y-m-d H:i:s', $time), new \DateTimeZone($tz ?: TIMEZONE)); $time = $f->diff(new \DateTime('now', new \DateTimeZone($tz ?: TIMEZONE)))->format('%a days %h hours %i min'); if (preg_match('/^(?:0 (?:days|hours) )+(.*)/', $time, $m)) { $time = $m[1]; } if ($max_parts) { $parts = explode(' ', $time); $time = ''; for ($i = 0; $i < $max_parts && $i < count($parts); $i += 2) { $time .= $parts[$i] . ' ' . $parts[$i + 1] . ' '; } } return trim($time); }
function getAll($year) { $r = array(); /** * Boucle version procédurale * $date = strtotime($year.'-01-01'); while(date('Y',$date) <= $year){ // Ce que je veux => $r[ANEEE][MOIS][JOUR] = JOUR DE LA SEMAINE $y = date('Y',$date); $m = date('n',$date); $d = date('j',$date); $w = str_replace('0','7',date('w',$date)); $r[$y][$m][$d] = $w; $date = strtotime(date('Y-m-d',$date).' +1 DAY'); } * * */ $date = new \DateTime($year . '-01-01'); while ($date->format('Y') <= $year) { // Ce que je veux => $r[ANEEE][MOIS][JOUR] = JOUR DE LA SEMAINE $y = $date->format('Y'); $m = $date->format('n'); $d = $date->format('j'); $w = str_replace('0', '7', $date->format('w')); $r[$y][$m][$d] = $w; $date->add(new \DateInterval('P1D')); } return $r; }
/** * Возвращает данные о вакансии * @param $jobId * @return array|void */ public function getVacancyDetails($jobId) { //получаем данные вакансии $data = $this->getRequestData("vacancies/{$jobId}", []); $vacancyData = []; $currentDate = date('Y-m-d'); $vacancyData['url'] = $data['alternate_url']; $vacancyData['cost'] = $this->getCost($data['salary']['from'], $data['salary']['to'], $data['salary']['currency']); $vacancyData['area_id'] = $data['area']['id']; $vacancyData['name'] = $data['name']; $vacancyData['parse_date'] = $currentDate; $publichedDate = new \DateTime($data['published_at']); $vacancyData['begda'] = $publichedDate->format('Y-m-d'); $vacancyData['endda'] = $currentDate; $vacancyData['vacancy_id'] = $jobId; $result = []; $result['vacancy_data'] = $vacancyData; $result['key_skills'] = $data['key_skills']; $result['parsed_skills'] = $this->getVacancySkillsFromText($data['description']); return $result; }
public function setDefaultValues() { /* Dane dotyczące utworzenia */ if ($this->isNewRecord) { if (!Yii::$app->user->isGuest && $this->hasAttribute('created_by')) { $this->created_by = Yii::$app->user->identity->id; } if ($this->hasAttribute('created_date')) { $this->created_date = \app\helpers\DateTime::now(); } } /* Dane dotyczące ostatniej modyfikacji */ if (!Yii::$app->user->isGuest && $this->hasAttribute('modified_by')) { $this->modified_by = Yii::$app->user->identity->id; } if ($this->hasAttribute('modified_date')) { $this->modified_date = \app\helpers\DateTime::now(); } }
<?php use app\helpers\DateTime; use obuhovski\blog\models\Post; use obuhovski\comments\models\Comment; use obuhovski\comments\models\User; use yii\helpers\Html; use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $comment array */ foreach ($comments as $comment) { $comment['created_at'] = DateTime::fromSql($comment['created_at'], 'd M Y в H:i'); ?> <div id="<?php echo $comment['id']; ?> " class="media" style="margin-left: <?php echo $comment['level'] * 50; ?> px"> <a href="" class="pull-left"> <img alt="" src="<?php echo $comment['avatar']; ?> " class="media-object"> </a> <div class="media-body"> <h4 class="media-heading"> <?php echo Html::encode($comment['username']);
<div class="nav"></div> </div> <!-- List Items (Specials Slider) | END --> <!-- Recent Blog Posts | START --> <div class="recent"> <?php foreach ($blog as $item) { ?> <a href="blog-post.html"> <div class="date"> <span class="month"><?php echo DateTime::blogOnMainMonth($item->created_at); ?> </span> <span class="day"><?php echo DateTime::blogOnMainDate($item->created_at); ?> </span> </div> <p class="title"><?php echo $item->title; ?> </p> <p><?php echo $item->short_description; ?> </p> </a> <?php } ?>
/** * * @param string $dateString * @param string $timeZone * @return string */ public static function dateToUTCFromTimezone($dateString, $timeZone = 'Europe/Berlin') { date_default_timezone_set($timeZone); $dateEu = new \DateTime($dateString); $dateEu->setTimezone(new \DateTimeZone('UTC')); return $dateEu->format('Y-m-d H:i:s'); }