今天获得科普特日期 [英] Get today coptic date
本文介绍了今天获得科普特日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望获取今天的科幻日期,使用任何代码类型,例如 php
或 javascript
显示我的网站标题的coptic日期。我需要用阿拉伯语或英语。
I'm looking to get coptic date of today with any code type like php
or javascript
to display coptic date to my site header. I need it in arabic or english.
我试图找到它,但没有发现任何类似英语的东西。
I have tried to find it, but didn't found any thing like it in english.
参考:
- http://www.copticchurch.net/easter.html
- http://www.ortelius.de/kalender/coptic_en.php
- http://en.wikipedia.org/wiki/Coptic_calendar
- http://www.copticchurch.net/easter.html
- http://www.ortelius.de/kalender/coptic_en.php
- http://en.wikipedia.org/wiki/Coptic_calendar
推荐答案
$dt = new CopticDateTime;
echo $dt->coptic(); # Tout 19, 1730
echo $dt->coptic('F j, Y'); # same as above (default)
echo $dt->coptic('d.m.Y'); # 19.01.1730
echo $dt->coptic('Y/n/j'); # 1730/1/19
由于这是DateTime类的扩展,你可以做所有类型的日期时间修改:
Since this is the extend of DateTime class, you can do all kind of date-time modifications :
$dt->modify('-2 year');
echo $dt->coptic(); # Tout 19, 1728
$dt->add(new DateInterval('P7Y5M4D'));
echo $dt->coptic(); # Amshir 26, 1735
# etc.
代码:
Code:
class CopticDateTime extends DateTime {
private $coptic_months = [
[ 1, 'Tout', '09-11', '09-12'],
[ 2, 'Baba', '10-11', '10-12'],
[ 3, 'Hator', '11-10', '11-11'],
[ 4, 'Kiahk', '12-10', '12-11'],
[ 5, 'Toba', '01-09', '01-10'],
[ 6, 'Amshir', '02-08', '02-09'],
[ 7, 'Baramhat', '03-10', '03-10'],
[ 8, 'Baramouda', '04-09', '04-09'],
[ 9, 'Bashans', '05-09', '05-09'],
[10, 'Paona', '06-08', '06-08'],
[11, 'Epep', '07-08', '07-08'],
[12, 'Mesra', '08-07', '08-07'],
[13, 'Nasie', '09-06', '09-06'],
];
public function coptic($format = 'F j, Y')
{
$year = $this->getCopticYear();
$month = $this->getCopticMonth();
$day = $this->getCopticDay($month);
$replace = [
'Y' => $year,
'F' => $month[1],
'n' => $month[0],
'm' => sprintf('%02d', $month[0]),
'j' => $day,
'd' => sprintf('%02d', $day),
];
$replaceKeys = array_map(function($r) { return '{' . $r .'}'; }, array_keys($replace));
$format = str_replace(array_keys($replace), $replaceKeys, $format);
return str_replace($replaceKeys, $replace, $format);
}
private function getCopticYear()
{
$dateColumn = $this->format('L') ? 3 : 2;
$date = $this->coptic_months[0][$dateColumn];
return $this->format('Y') - 283 - ($this->format('m-d') < $date ? 1 : 0);
}
private function getCopticMonth()
{
$dateColumn = $this->format('L') ? 3 : 2;
$date = $this->format('m-d');
$month = null;
foreach ($this->coptic_months as $copticMonth) {
if ($date >= $copticMonth[$dateColumn]) {
$month = $copticMonth;
if ($copticMonth[$dateColumn] >= '12-00') break;
} elseif ($month) {
break;
}
}
if (!$month) {
$month = $this->coptic_months[3];
}
return $month;
}
private function getCopticDay(array $month)
{
$dateColumn = $this->format('L') ? 3 : 2;
$monthDateTime = clone $this;
list($m, $d) = explode('-', $month[$dateColumn]);
$monthDateTime->setDate($this->format('Y'), $m, $d);
if ($monthDateTime > $this) $monthDateTime->modify('-1 year');
return $monthDateTime->diff($this)->days + 1;
}
}
此代码没有'由于闰年,在1900年以后的日期工作正常。
这篇关于今天获得科普特日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文