编程语言
首页 > 编程语言> > 如何用PHP今天打印尼泊尔日期?

如何用PHP今天打印尼泊尔日期?

作者:互联网

我想在不同的日期格式上回显打印尼泊尔日历日期.
请看下面的代码

并为此提供了一个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');?>  &nbsp;| &nbsp; <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>&nbsp;|&nbsp; <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("&#2406;", "&#2407;", "&#2408;", "&#2409;", "&#2410;", "&#2411;", "&#2412;", "&#2413;", "&#2414;", "&#2415;");
        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日,星期三| ,ार,माघ२२,२०७० | ०७:३६:४५ PM

我想打印:2070-10-22

解决方法:

这是获取尼泊尔语日期的一个小技巧:

<?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+०५:४५

标签:date-conversion,php,date
来源: https://codeday.me/bug/20191010/1888225.html