Sum*_*K.C 6 php date date-conversion
尼泊尔日期:今天是:2070-10-21(YYYY-MM-DD)
并且有一个jquery日期选择器:http: //sajanmaharjan.com.np/my-works/nepali-datepicker-ui/
现在,我想要的是打印2070-10-21作为今天的日期.(如(date(ymd)返回英文日期)
我试过的是这个:这回来了
<div id="time">
<!-- PRINTING NEPALI DATE AND TIME -->
<span class="time_date">
<?php
$timezone = "Asia/Kathmandu";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
echo date('l F j, Y');?> | <script type='text/javascript'>var __ndq = __ndq || {format:'W, M D, Y',color:'#555555'};var __sn = document.getElementsByTagName('script'); __sn = __sn[__sn.length-1];(function() {var __nd = document.createElement('script'); __nd.type = 'text/javascript'; __nd.async = true; __nd.src = ('http://') + 'goodies.softnep.com/nepali_date/nep.date.js'; __sn.parentNode.insertBefore(__nd, __sn);})();</script> | <span id="sn_nepalitime"></span></span>
<script type="text/javascript">
var currenttime = "<?php echo date('M-d,Y h:i:s');?>"; <!--"November 20, 2013 13:19:32"-->
var montharray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
var numbers = Array("०", "१", "२", "३", "४", "५", "६", "७", "८", "९");
var serverdate = new Date(currenttime);
function padlength(what) {
var output = (what.toString().length == 1) ? "0" + what : what
return output
}
function displaytime() {
//alert(currenttime);
serverdate.setSeconds(serverdate.getSeconds() + 1)
var datestring = montharray[serverdate.getMonth()] + " " + padlength(serverdate.getDate()) + ", " + serverdate.getFullYear()
hr=padlength(serverdate.getHours());
mi=padlength(serverdate.getMinutes()) ;
se=padlength(serverdate.getSeconds());
dd="PM";
if (hr >= 12) {
hr = hr-12;
dd = "AM";
}
if (hr == 0) {
hr = 12;
}
var timestring = hr + ":" + mi + ":" + se +" "+ dd;
var arr = timestring.split("");
for (i = 0; i < (arr.length-3); i++) {
if (arr[i] != ":") {
arr[i] = numbers[arr[i]];
}
}
timestring = arr.join("");
/* timestring = timestring.replace("AM","gu");
timestring = timestring.replace("PM","gu");*/
document.getElementById("sn_nepalitime").innerHTML = " " + timestring;
setTimeout('displaytime()',1000);
}
displaytime();
</script>
<!-- END OF NEPALI DATE AND TIME -->
</div>
Run Code Online (Sandbox Code Playgroud)
打印:2014年2月5日星期三| बुधवार,माघ22,2070 | 07:36:45 PM
我希望它打印:2070-10-22
这是获取尼泊尔语日期的小技巧:
\n\n<?php\n\nheader(\'Content-Type: text/plain; charset=utf-8\');\n\n$formats = array(\n IntlDateFormatter::NONE => \'IntlDateFormatter::NONE\',\n IntlDateFormatter::SHORT => \'IntlDateFormatter::SHORT\',\n IntlDateFormatter::MEDIUM => \'IntlDateFormatter::MEDIUM\',\n IntlDateFormatter::LONG => \'IntlDateFormatter::LONG\',\n IntlDateFormatter::FULL => \'IntlDateFormatter::FULL\',\n);\n$locale = \'ne_NP\';\n$time_zone = \'Asia/Katmandu\';\n\nforeach($formats as $format => $label){\n echo $label . PHP_EOL;\n $fmt = new IntlDateFormatter($locale, $format, $format, $time_zone, IntlDateFormatter::GREGORIAN);\n echo $fmt->format(new DateTime) . PHP_EOL;\n echo PHP_EOL;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n<?php\n\nheader(\'Content-Type: text/plain; charset=utf-8\');\n\n$formats = array(\n IntlDateFormatter::NONE => \'IntlDateFormatter::NONE\',\n IntlDateFormatter::SHORT => \'IntlDateFormatter::SHORT\',\n IntlDateFormatter::MEDIUM => \'IntlDateFormatter::MEDIUM\',\n IntlDateFormatter::LONG => \'IntlDateFormatter::LONG\',\n IntlDateFormatter::FULL => \'IntlDateFormatter::FULL\',\n);\n$locale = \'ne_NP\';\n$time_zone = \'Asia/Katmandu\';\n\nforeach($formats as $format => $label){\n echo $label . PHP_EOL;\n $fmt = new IntlDateFormatter($locale, $format, $format, $time_zone, IntlDateFormatter::GREGORIAN);\n echo $fmt->format(new DateTime) . PHP_EOL;\n echo PHP_EOL;\n}\nRun Code Online (Sandbox Code Playgroud)\n