- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在处理尼泊尔日期。由于月末后面没有简单的逻辑,它可以是 29、30、31 和 32。在特定逻辑中,我不需要两个日期之间的天数。
我试过以下代码:
$from = '2076-07-15';
$to = '2076-07-30';
$from_array = explode('-', $from);
$to_array = explode('-', $to);
$days = $to_array[2] - $from_array[2];
$from = '2076-07-01';
$to = '2076-07-15';
From To Required Current
2076-07-01 2076-07-15 => 15 days 14 days -----> Incorrect
2076-07-15 2076-07-30 => 15 days 15 days ------> Correct
2076-07-01 2076-07-30 => 30 days 29 days ------> Incorrect
最佳答案
将此代码复制并粘贴到您可以访问的某个位置,并使用提供的最后一个示例方法。这会将尼泊尔语转换为英语,反之亦然。然后使用 Carbon 减去日期。
Nepali into english and vice versa converter
<?php
namespace App\Helper;
class Nepali_Calendar
{
// Data for nepali date
private $_bs = array(
0 => array(2000,30,32,31,32,31,30,30,30,29,30,29,31),
1 => array(2001,31,31,32,31,31,31,30,29,30,29,30,30),
2 => array(2002,31,31,32,32,31,30,30,29,30,29,30,30),
3 => array(2003,31,32,31,32,31,30,30,30,29,29,30,31),
4 => array(2004,30,32,31,32,31,30,30,30,29,30,29,31),
5 => array(2005,31,31,32,31,31,31,30,29,30,29,30,30),
6 => array(2006,31,31,32,32,31,30,30,29,30,29,30,30),
7 => array(2007,31,32,31,32,31,30,30,30,29,29,30,31),
8 => array(2008,31,31,31,32,31,31,29,30,30,29,29,31),
9 => array(2009,31,31,32,31,31,31,30,29,30,29,30,30),
10 => array(2010,31,31,32,32,31,30,30,29,30,29,30,30),
11 => array(2011,31,32,31,32,31,30,30,30,29,29,30,31),
12 => array(2012,31,31,31,32,31,31,29,30,30,29,30,30),
13 => array(2013,31,31,32,31,31,31,30,29,30,29,30,30),
14 => array(2014,31,31,32,32,31,30,30,29,30,29,30,30),
15 => array(2015,31,32,31,32,31,30,30,30,29,29,30,31),
16 => array(2016,31,31,31,32,31,31,29,30,30,29,30,30),
17 => array(2017,31,31,32,31,31,31,30,29,30,29,30,30),
18 => array(2018,31,32,31,32,31,30,30,29,30,29,30,30),
19 => array(2019,31,32,31,32,31,30,30,30,29,30,29,31),
20 => array(2020,31,31,31,32,31,31,30,29,30,29,30,30),
21 => array(2021,31,31,32,31,31,31,30,29,30,29,30,30),
22 => array(2022,31,32,31,32,31,30,30,30,29,29,30,30),
23 => array(2023,31,32,31,32,31,30,30,30,29,30,29,31),
24 => array(2024,31,31,31,32,31,31,30,29,30,29,30,30),
25 => array(2025,31,31,32,31,31,31,30,29,30,29,30,30),
26 => array(2026,31,32,31,32,31,30,30,30,29,29,30,31),
27 => array(2027,30,32,31,32,31,30,30,30,29,30,29,31),
28 => array(2028,31,31,32,31,31,31,30,29,30,29,30,30),
29 => array(2029,31,31,32,31,32,30,30,29,30,29,30,30),
30 => array(2030,31,32,31,32,31,30,30,30,29,29,30,31),
31 => array(2031,30,32,31,32,31,30,30,30,29,30,29,31),
32 => array(2032,31,31,32,31,31,31,30,29,30,29,30,30),
33 => array(2033,31,31,32,32,31,30,30,29,30,29,30,30),
34 => array(2034,31,32,31,32,31,30,30,30,29,29,30,31),
35 => array(2035,30,32,31,32,31,31,29,30,30,29,29,31),
36 => array(2036,31,31,32,31,31,31,30,29,30,29,30,30),
37 => array(2037,31,31,32,32,31,30,30,29,30,29,30,30),
38 => array(2038,31,32,31,32,31,30,30,30,29,29,30,31),
39 => array(2039,31,31,31,32,31,31,29,30,30,29,30,30),
40 => array(2040,31,31,32,31,31,31,30,29,30,29,30,30),
41 => array(2041,31,31,32,32,31,30,30,29,30,29,30,30),
42 => array(2042,31,32,31,32,31,30,30,30,29,29,30,31),
43 => array(2043,31,31,31,32,31,31,29,30,30,29,30,30),
44 => array(2044,31,31,32,31,31,31,30,29,30,29,30,30),
45 => array(2045,31,32,31,32,31,30,30,29,30,29,30,30),
46 => array(2046,31,32,31,32,31,30,30,30,29,29,30,31),
47 => array(2047,31,31,31,32,31,31,30,29,30,29,30,30),
48 => array(2048,31,31,32,31,31,31,30,29,30,29,30,30),
49 => array(2049,31,32,31,32,31,30,30,30,29,29,30,30),
50 => array(2050,31,32,31,32,31,30,30,30,29,30,29,31),
51 => array(2051,31,31,31,32,31,31,30,29,30,29,30,30),
52 => array(2052,31,31,32,31,31,31,30,29,30,29,30,30),
53 => array(2053,31,32,31,32,31,30,30,30,29,29,30,30),
54 => array(2054,31,32,31,32,31,30,30,30,29,30,29,31),
55 => array(2055,31,31,32,31,31,31,30,29,30,29,30,30),
56 => array(2056,31,31,32,31,32,30,30,29,30,29,30,30),
57 => array(2057,31,32,31,32,31,30,30,30,29,29,30,31),
58 => array(2058,30,32,31,32,31,30,30,30,29,30,29,31),
59 => array(2059,31,31,32,31,31,31,30,29,30,29,30,30),
60 => array(2060,31,31,32,32,31,30,30,29,30,29,30,30),
61 => array(2061,31,32,31,32,31,30,30,30,29,29,30,31),
62 => array(2062,30,32,31,32,31,31,29,30,29,30,29,31),
63 => array(2063,31,31,32,31,31,31,30,29,30,29,30,30),
64 => array(2064,31,31,32,32,31,30,30,29,30,29,30,30),
65 => array(2065,31,32,31,32,31,30,30,30,29,29,30,31),
66 => array(2066,31,31,31,32,31,31,29,30,30,29,29,31),
67 => array(2067,31,31,32,31,31,31,30,29,30,29,30,30),
68 => array(2068,31,31,32,32,31,30,30,29,30,29,30,30),
69 => array(2069,31,32,31,32,31,30,30,30,29,29,30,31),
70 => array(2070,31,31,31,32,31,31,29,30,30,29,30,30),
71 => array(2071,31,31,32,31,31,31,30,29,30,29,30,30),
72 => array(2072,31,32,31,32,31,30,30,29,30,29,30,30),
73 => array(2073,31,32,31,32,31,30,30,30,29,29,30,31),
74 => array(2074,31,31,31,32,31,31,30,29,30,29,30,30),
75 => array(2075,31,31,32,31,31,31,30,29,30,29,30,30),
76 => array(2076,31,32,31,32,31,30,30,30,29,29,30,30),
77 => array(2077,31,32,31,32,31,30,30,30,29,30,29,31),
78 => array(2078,31,31,31,32,31,31,30,29,30,29,30,30),
79 => array(2079,31,31,32,31,31,31,30,29,30,29,30,30),
80 => array(2080,31,32,31,32,31,30,30,30,29,29,30,30),
81 => array(2081,31,31,32,32,31,30,30,30,29,30,30,30),
82 => array(2082,30,32,31,32,31,30,30,30,29,30,30,30),
83 => array(2083,31,31,32,31,31,30,30,30,29,30,30,30),
84 => array(2084,31,31,32,31,31,30,30,30,29,30,30,30),
85 => array(2085,31,32,31,32,30,31,30,30,29,30,30,30),
86 => array(2086,30,32,31,32,31,30,30,30,29,30,30,30),
87 => array(2087,31,31,32,31,31,31,30,30,29,30,30,30),
88 => array(2088,30,31,32,32,30,31,30,30,29,30,30,30),
89 => array(2089,30,32,31,32,31,30,30,30,29,30,30,30),
90 => array(2090,30,32,31,32,31,30,30,30,29,30,30,30)
);
private $_nep_date = array('year' => '', 'month' => '', 'date' => '', 'day' => '', 'nmonth' => '', 'num_day' => '');
private $_eng_date = array('year' => '', 'month' => '', 'date' => '', 'day' => '', 'emonth' => '', 'num_day' => '');
public $debug_info = "";
/**
* Return day
*
* @param int $day
* @return string
*/
private function _get_day_of_week($day)
{
switch ($day)
{
case 1:
$day = "Sunday";
break;
case 2:
$day = "Monday";
break;
case 3:
$day = "Tuesday";
break;
case 4:
$day = "Wednesday";
break;
case 5:
$day = "Thursday";
break;
case 6:
$day = "Friday";
break;
case 7:
$day = "Saturday";
break;
}
return $day;
}
/**
* Return english month name
*
* @param int $m
* @return string
*/
private function _get_english_month($m)
{
$eMonth = FALSE;
switch ($m)
{
case 1:
$eMonth = "January";
break;
case 2:
$eMonth = "February";
break;
case 3:
$eMonth = "March";
break;
case 4:
$eMonth = "April";
break;
case 5:
$eMonth = "May";
break;
case 6:
$eMonth = "June";
break;
case 7:
$eMonth = "July";
break;
case 8:
$eMonth = "August";
break;
case 9:
$eMonth = "September";
break;
case 10:
$eMonth = "October";
break;
case 11:
$eMonth = "November";
break;
case 12:
$eMonth = "December";
}
return $eMonth;
}
/**
* Return nepali month name
*
* @param int $m
* @return string
*/
private function _get_nepali_month($m)
{
$n_month = FALSE;
switch ($m)
{
case 1:
$n_month = "Baishak";
break;
case 2:
$n_month = "Jestha";
break;
case 3:
$n_month = "Ashad";
break;
case 4:
$n_month = "Shrawn";
break;
case 5:
$n_month = "Bhadra";
break;
case 6:
$n_month = "Ashwin";
break;
case 7:
$n_month = "kartik";
break;
case 8:
$n_month = "Mangshir";
break;
case 9:
$n_month = "Poush";
break;
case 10:
$n_month = "Magh";
break;
case 11:
$n_month = "Falgun";
break;
case 12:
$n_month = "Chaitra";
break;
}
return $n_month;
}
/**
* Check if date range is in english
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return bool
*/
private function _is_in_range_eng($yy, $mm, $dd)
{
if ($yy < 1944 || $yy > 2033)
{
return 'Supported only between 1944-2022';
}
if ($mm < 1 || $mm > 12)
{
return 'Error! month value can be between 1-12 only';
}
if ($dd < 1 || $dd > 31)
{
return 'Error! day value can be between 1-31 only';
}
return TRUE;
}
/**
* Check if date is with in nepali data range
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return bool
*/
private function _is_in_range_nep($yy, $mm, $dd)
{
if ($yy < 2000 || $yy > 2089)
{
return 'Supported only between 2000-2089';
}
if ($mm < 1 || $mm > 12)
{
return 'Error! month value can be between 1-12 only';
}
if ($dd < 1 || $dd > 32)
{
return 'Error! day value can be between 1-31 only';
}
return TRUE;
}
/**
* Calculates wheather english year is leap year or not
*
* @param int $year
* @return bool
*/
public function is_leap_year($year)
{
$a = $year;
if ($a % 100 == 0)
{
if ($a % 400 == 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
else
{
if ($a % 4 == 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
}
/**
* currently can only calculate the date between AD 1944-2033...
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return array
*/
public function eng_to_nep($yy, $mm, $dd)
{
// Check for date range
$chk = $this->_is_in_range_eng($yy, $mm, $dd);
if($chk !== TRUE)
{
die($chk);
}
else
{
// Month data.
$month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
// Month for leap year
$lmonth = array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$def_eyy = 1944; // initial english date.
$def_nyy = 2000;
$def_nmm = 9;
$def_ndd = 17 - 1; // inital nepali date.
$total_eDays = 0;
$total_nDays = 0;
$a = 0;
$day = 7 - 1;
$m = 0;
$y = 0;
$i = 0;
$j = 0;
$numDay = 0;
// Count total no. of days in-terms year
for ($i = 0; $i < ($yy - $def_eyy); $i++) //total days for month calculation...(english)
{
if ($this->is_leap_year($def_eyy + $i) === TRUE)
{
for ($j = 0; $j < 12; $j++)
{
$total_eDays += $lmonth[$j];
}
}
else
{
for ($j = 0; $j < 12; $j++)
{
$total_eDays += $month[$j];
}
}
}
// Count total no. of days in-terms of month
for ($i = 0; $i < ($mm - 1); $i++)
{
if ($this->is_leap_year($yy) === TRUE)
{
$total_eDays += $lmonth[$i];
}
else
{
$total_eDays += $month[$i];
}
}
// Count total no. of days in-terms of date
$total_eDays += $dd;
$i = 0;
$j = $def_nmm;
$total_nDays = $def_ndd;
$m = $def_nmm;
$y = $def_nyy;
// Count nepali date from array
while ($total_eDays != 0)
{
$a = $this->_bs[$i][$j];
$total_nDays++; //count the days
$day++; //count the days interms of 7 days
if ($total_nDays > $a)
{
$m++;
$total_nDays = 1;
$j++;
}
if ($day > 7)
{
$day = 1;
}
if ($m > 12)
{
$y++;
$m = 1;
}
if ($j > 12)
{
$j = 1;
$i++;
}
$total_eDays--;
}
$numDay = $day;
$this->_nep_date['year'] = $y;
$this->_nep_date['month'] = $m;
$this->_nep_date['date'] = $total_nDays;
$this->_nep_date['day'] = $this->_get_day_of_week($day);
$this->_nep_date['nmonth'] = $this->_get_nepali_month($m);
$this->_nep_date['num_day'] = $numDay;
return $this->_nep_date;
}
}
/**
* Currently can only calculate the date between BS 2000-2089
*
* @param int $yy
* @param int $mm
* @param int $dd
* @return array
*/
public function nep_to_eng($yy, $mm, $dd)
{
$def_eyy = 1943;
$def_emm = 4;
$def_edd = 14 - 1; // initial english date.
$def_nyy = 2000;
$def_nmm = 1;
$def_ndd = 1; // iniital equivalent nepali date.
$total_eDays = 0;
$total_nDays = 0;
$a = 0;
$day = 4 - 1;
$m = 0;
$y = 0;
$i = 0;
$k = 0;
$numDay = 0;
$month = array(
0,
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
);
$lmonth = array(
0,
31,
29,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
);
// Check for date range
$chk = $this->_is_in_range_nep($yy, $mm, $dd);
if ( $chk !== TRUE)
{
die($chk);
}
else
{
// Count total days in-terms of year
for ($i = 0; $i < ($yy - $def_nyy); $i++)
{
for ($j = 1; $j <= 12; $j++)
{
$total_nDays += $this->_bs[$k][$j];
}
$k++;
}
// Count total days in-terms of month
for ($j = 1; $j < $mm; $j++)
{
$total_nDays += $this->_bs[$k][$j];
}
// Count total days in-terms of dat
$total_nDays += $dd;
// Calculation of equivalent english date...
$total_eDays = $def_edd;
$m = $def_emm;
$y = $def_eyy;
while ($total_nDays != 0)
{
if ($this->is_leap_year($y))
{
$a = $lmonth[$m];
}
else
{
$a = $month[$m];
}
$total_eDays++;
$day++;
if ($total_eDays > $a)
{
$m++;
$total_eDays = 1;
if ($m > 12)
{
$y++;
$m = 1;
}
}
if ($day > 7)
{
$day = 1;
}
$total_nDays--;
}
$numDay = $day;
$this->_eng_date['year'] = $y;
$this->_eng_date['month'] = $m;
$this->_eng_date['date'] = $total_eDays;
$this->_eng_date['day'] = $this->_get_day_of_week($day);
$this->_eng_date['nmonth'] = $this->_get_english_month($m);
$this->_eng_date['num_day'] = $numDay;
return $this->_eng_date;
}
}
}
// Example:
// $cal = new Nepali_Calendar();
// print_r ($cal->eng_to_nep(2008,11,23));
// print_r($cal->nep_to_eng(2065,8,8));
关于php - 在laravel中计算两个日期之间的天数的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59043806/
SQL 和一般开发的新手,我有一个表(COUNTRIES),其中包含字段(INDEX、NAME、POPULATION、AREA) 通常我添加一个客户端(Delphi)计算字段(DENSITY)和 On
我想使用 calc(100%-100px),但在我的 demo 中不起作用由于高度只接受像素,因此如何将此百分比值转换为像素。 最佳答案 以下将为您提供高度: $(window).height();
我正在尝试在 MySQL 中添加列并动态填充其他列。 例如我有一张表“数字”并具有第 1 列、第 2 列、第 3 列,这些总数应填充在第 4 列中 最佳答案 除非我误解了你的问题,否则你不只是在寻找:
我想返回简单计算的结果,但我不确定如何执行此操作。我的表格如下: SELECT COUNT(fb.engineer_id) AS `total_feedback`, SUM(fb.ra
我一直在尝试做这个程序,但我被卡住了,我仍然是一个初学者,任何帮助将不胜感激。我需要程序来做 打印一个 10 X 10 的表格,其中表格中的每个条目都是行号和列号的总和 包含一个累加器,用于计算所有表
这个计算背后一定有一些逻辑。但我无法得到它。普通数学不会导致这种行为。谁能帮我解释一下原因 printf ("float %f\n", 2/7 * 100.0); 结果打印 1.000000 为什么会
我想计算从 0 到 (n)^{1/2} - 1 的数字的 AND每个数字从 0 到 (n)^{1/2} - 1 .我想在 O(n) 中执行此操作时间,不能使用 XOR、OR、AND 运算。 具体来说,
如何在 Excel 中将公式放入自定义数字格式?例如(出于说明目的随机示例), 假设我有以下数据: 输入 输出 在不编辑单元格中的实际数据的情况下,我想显示单元格中的值除以 2,并保留两位小数: 有没
每次我在 Flutter 应用程序中调用计算()时,我都会看到内存泄漏,据我所知,这基本上只是一种生成隔离的便捷方法。我的应用程序内存占用增加并且在 GC 之后永远不会减少。 我已将我的代码简化为仅调
我有数字特征观察 V1通过 V12用于目标变量 Wavelength .我想计算 Vx 之间的 RMSE列。数据格式如下。 每个变量“Vx”以 5 分钟的间隔进行测量。我想计算所有 Vx 变量的观测值
我正在寻找一种使用 C 语言计算文件中未知字符数的简单方法。谢谢你的帮助 最佳答案 POSIX 方式(可能是您想要的方式): off_t get_file_length( FILE *file ) {
我正在使用 Postgres,并且我正试图围绕如何在连续日期跨度中得出第一个开始日期的问题进行思考。例如 :- ID | Start Date | End Date =================
我有一个订单表格,我在其中使用 jQuery 计算插件来汇总总数。 此求和工作正常,但生成的“总和”存在问题。总之,我希望用逗号替换任何点。 代码的基础是; function ($this) {
我在使用 double 变量计算简单算术方程时遇到问题。 我有一个具有 double 属性 Value 的组件,我将此属性设置为 100。 然后我做一个简单的减法来检查这个值是否真的是 100: va
我在这里看到了一些关于 CRC 32 计算的其他问题。但没有一个让我满意,因此是这样。 openssl 库是否有任何用于计算 CRC32 的 api 支持?我已经在为 SHA1 使用 openssl,
当我在PHP日期计算中遇到问题时,我感到惊讶。 $add = '- 30 days'; echo date('Y-m-01', strtotime($add)); // result is 2017-
我正在使用 javascript 进行练习,我编写了这个脚本来计算 2 个变量的总和,然后在第三个方程中使用这个总和!关于如何完成这项工作的任何想法都将非常有用! First Number:
我有一个来自EAC的提示单和一个包含完整专辑的FLAC文件。 我正在尝试制作一些python脚本来播放文件,因为我需要能够设置在flac文件中开始的位置。 如何从CueSheet格式MM:SS:FF转
这个问题已经有答案了: Adding two numbers concatenates them instead of calculating the sum (24 个回答) 已关闭去年。 我有一个
4000 我需要上面字段 name="quantity" 和 id="price" 中的值,并使用 javascript 函数进行计算,并将其显示在字段 id= 中仅当我单击计算按钮时才显示“总
我是一名优秀的程序员,十分优秀!