我希望以不同的日期格式回显打印尼泊尔日历日期。 请看下面的代码
还有一个jquery日期选择器: http://sajanmaharjan.com.np/my-works/nepali-datepicker-ui/
现在,我想要的是打印2070-10-21作为今天的日期。 (如(date(y-m-d)返回英文日期)
我试过的是这个:
<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>
打印:2014年2月5日星期三| बुधवार,माघ22,2070 | 07:36:45 PM
我想要打印:2070-10-22
答案 0 :(得分:4)
这是获取尼泊尔语日期的一个小技巧:
<?php
header('Content-Type: text/plain; charset=utf-8');
$formats = array(
IntlDateFormatter::NONE => 'IntlDateFormatter::NONE',
IntlDateFormatter::SHORT => 'IntlDateFormatter::SHORT',
IntlDateFormatter::MEDIUM => 'IntlDateFormatter::MEDIUM',
IntlDateFormatter::LONG => 'IntlDateFormatter::LONG',
IntlDateFormatter::FULL => 'IntlDateFormatter::FULL',
);
$locale = 'ne_NP';
$time_zone = 'Asia/Katmandu';
foreach($formats as $format => $label){
echo $label . PHP_EOL;
$fmt = new IntlDateFormatter($locale, $format, $format, $time_zone, IntlDateFormatter::GREGORIAN);
echo $fmt->format(new DateTime) . PHP_EOL;
echo PHP_EOL;
}
IntlDateFormatter::NONE
२०१४०२०४ ०६:१७ उत्तर मध्यान्ह
IntlDateFormatter::SHORT
२०१४-०२-०४ १८:१७
IntlDateFormatter::MEDIUM
२०१४ फेब ४ १८:१७:०९
IntlDateFormatter::LONG
२०१४ फेब्रुअरी ४ १८:१७:०९ GMT+५:४५
IntlDateFormatter::FULL
२०१४ फेब्रुअरी ४, मङ्गलबार १८:१७:०९ GMT+०५:४५