function jdate($type, $maket = "now") { //set 1 if you want translate number to farsi or if you don't like set 0 //$transnumber = 0; ///chosse your timezone $TZhours = 3; $TZminute = 30; $need = ""; $result1 = ""; $result = ""; if ($maket == "now") { $year = date("Y"); $month = date("m"); $day = date("d"); list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); $maket = mktime(date("H") + $TZhours, date("i") + $TZminute, date("s"), date("m"), date("d"), date("Y")); } else { //$maket=0; $maket += $TZhours * 3600 + $TZminute * 60; $date = date("Y-m-d", $maket); list($year, $month, $day) = preg_split('/-/', $date); list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); } $need = $maket; $year = date("Y", $need); $month = date("m", $need); $day = date("d", $need); $i = 0; $subtype = ""; $subtypetemp = ""; list($jyear, $jmonth, $jday) = gregorian_to_jalali($year, $month, $day); while ($i < strlen($type)) { $subtype = substr($type, $i, 1); if ($subtypetemp == "\\") { $result .= $subtype; $i++; continue; } switch ($subtype) { case "A": $result1 = date("a", $need); if ($result1 == "pm") { $result .= "بعدازظهر"; } else { $result .= "قبل‏ازظهر"; } break; case "a": $result1 = date("a", $need); if ($result1 == "pm") { $result .= "ب.ظ"; } else { $result .= "ق.ظ"; } break; case "d": if ($jday < 10) { $result1 = "0" . $jday; } else { $result1 = $jday; } if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "D": $result1 = date("D", $need); if ($result1 == "Thu") { $result1 = "پ"; } else { if ($result1 == "Sat") { $result1 = "ش"; } else { if ($result1 == "Sun") { $result1 = "ى"; } else { if ($result1 == "Mon") { $result1 = "د"; } else { if ($result1 == "Tue") { $result1 = "س"; } else { if ($result1 == "Wed") { $result1 = "چ"; } else { if ($result1 == "Thu") { $result1 = "پ"; } else { if ($result1 == "Fri") { $result1 = "ج"; } } } } } } } } $result .= $result1; break; case "F": $result .= monthname($jmonth); break; case "g": $result1 = date("g", $need); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "G": $result1 = date("G", $need); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "h": $result1 = date("h", $need); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "H": $result1 = date("H", $need); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "i": $result1 = date("i", $need); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "j": $result1 = $jday; if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "l": $result1 = date("l", $need); if ($result1 == "Saturday") { $result1 = "شنبه"; } else { if ($result1 == "Sunday") { $result1 = "یکشنبه"; } else { if ($result1 == "Monday") { $result1 = "دوشنبه"; } else { if ($result1 == "Tuesday") { $result1 = "سهشنبه"; } else { if ($result1 == "Wednesday") { $result1 = "جهارشنبه"; } else { if ($result1 == "Thursday") { $result1 = "پنجشنبه"; } else { if ($result1 == "Friday") { $result1 = "جمعه"; } } } } } } } $result .= $result1; break; case "m": if ($jmonth < 10) { $result1 = "0" . $jmonth; } else { $result1 = $jmonth; } if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "M": $result .= short_monthname($jmonth); break; case "n": $result1 = $jmonth; if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "s": $result1 = date("s", $need); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "S": $result .= ""; break; case "t": $result .= lastday($month, $day, $year); break; case "w": $result1 = date("w", $need); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "y": $result1 = substr($jyear, 2, 4); if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "Y": $result1 = $jyear; if ($transnumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "U": $result .= mktime(); break; case "Z": $result .= days_of_year($jmonth, $jday, $jyear); break; case "L": list($tmp_year, $tmp_month, $tmp_day) = jalali_to_gregorian(1384, 12, 1); echo $tmp_day; /*if(lastday($tmp_month,$tmp_day,$tmp_year)=="31") $result.="1"; else $result.="0"; */ break; default: $result .= $subtype; } $subtypetemp = substr($type, $i, 1); $i++; } return $result; }
function mds_date($format, $when = "now", $persianNumber = 0) { ///chosse your timezone $TZhours = 0; $TZminute = 0; $need = ""; $result1 = ""; $result = ""; if ($when == "now") { $year = date("Y"); $month = date("m"); $day = date("d"); list($Dyear, $Dmonth, $Dday) = gregorian_to_mds($year, $month, $day); $when = mktime(date("H") + $TZhours, date("i") + $TZminute, date("s"), date("m"), date("d"), date("Y")); } else { //$when=0; $when += $TZhours * 3600 + $TZminute * 60; $date = date("Y-m-d", $when); list($year, $month, $day) = preg_split('/-/', $date); list($Dyear, $Dmonth, $Dday) = gregorian_to_mds($year, $month, $day); } $need = $when; $year = date("Y", $need); $month = date("m", $need); $day = date("d", $need); $i = 0; $subtype = ""; $subtypetemp = ""; list($Dyear, $Dmonth, $Dday) = gregorian_to_mds($year, $month, $day); while ($i < strlen($format)) { $subtype = substr($format, $i, 1); if ($subtypetemp == "\\") { $result .= $subtype; $i++; continue; } switch ($subtype) { case "A": $result1 = date("a", $need); if ($result1 == "pm") { $result .= "بعدازظهر"; } else { $result .= "قبل‏ازظهر"; } break; case "a": $result1 = date("a", $need); if ($result1 == "pm") { $result .= "ب.ظ"; } else { $result .= "ق.ظ"; } break; case "d": if ($Dday < 10) { $result1 = "0" . $Dday; } else { $result1 = $Dday; } if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "D": $result1 = date("D", $need); if ($result1 == "Thu") { $result1 = "پ"; } else { if ($result1 == "Sat") { $result1 = "ش"; } else { if ($result1 == "Sun") { $result1 = "ى"; } else { if ($result1 == "Mon") { $result1 = "د"; } else { if ($result1 == "Tue") { $result1 = "س"; } else { if ($result1 == "Wed") { $result1 = "چ"; } else { if ($result1 == "Thu") { $result1 = "پ"; } else { if ($result1 == "Fri") { $result1 = "ج"; } } } } } } } } $result .= $result1; break; case "F": $result .= monthname($Dmonth); break; case "g": $result1 = date("g", $need); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "G": $result1 = date("G", $need); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "h": $result1 = date("h", $need); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "H": $result1 = date("H", $need); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "i": $result1 = date("i", $need); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "j": $result1 = $Dday; if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "l": $result1 = date("l", $need); if ($result1 == "Saturday") { $result1 = "شنبه"; } else { if ($result1 == "Sunday") { $result1 = "يكشنبه"; } else { if ($result1 == "Monday") { $result1 = "دوشنبه"; } else { if ($result1 == "Tuesday") { $result1 = "سه شنبه"; } else { if ($result1 == "Wednesday") { $result1 = "چهارشنبه"; } else { if ($result1 == "Thursday") { $result1 = "پنجشنبه"; } else { if ($result1 == "Friday") { $result1 = "جمعه"; } } } } } } } $result .= $result1; break; case "m": if ($Dmonth < 10) { $result1 = "0" . $Dmonth; } else { $result1 = $Dmonth; } if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "M": $result .= short_monthname($Dmonth); break; case "n": $result1 = $Dmonth; if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "s": $result1 = date("s", $need); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "S": $result .= "ام"; break; case "t": $result .= lastday($month, $day, $year); break; case "w": $result1 = date("w", $need); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "y": $result1 = substr($Dyear, 2, 4); if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "Y": $result1 = $Dyear; if ($persianNumber == 1) { $result .= Convertnumber2farsi($result1); } else { $result .= $result1; } break; case "U": $result .= mktime(); break; case "Z": $result .= days_of_year($Dmonth, $Dday, $Dyear); break; case "L": list($tmp_year, $tmp_month, $tmp_day) = mds_to_gregorian(1384, 12, 1); echo $tmp_day; /*if(lastday($tmp_month,$tmp_day,$tmp_year)=="31") $result.="1"; else $result.="0"; */ break; default: $result .= $subtype; } $subtypetemp = substr($format, $i, 1); $i++; } return $result; }