หมวด บอร์ดทั่วไป
> สารพันความรู้ - เทคโนโลยี

smf เปลี่ยนปี คศ. เป็น พศ.

(1/1)

ลุงเปี๊ยก ที-เน็ตเวิร์ค (อ.สากเหล็ก):

smf เปลี่ยนปี คศ. เป็น พศ.

เข้าไปที่...
.../ Sources/ Subs.php

ค้นหาคำว่า...

--- โค๊ด: ---// Do-it-yourself time localization.  Fun.
--- ปิดโค้ด ---

เอาโค้ดนี้...วางก่อนหน้า

--- โค๊ด: ---// Convert Common Era (C.E.) into Buddhist Era (B.E., aka Thai year)
    $time_array = getdate( $time );
    $str = str_replace( '%y', ( $time_array['year'] + 543 ) % 100, $str );
    $str = str_replace( '%Y', $time_array['year'] + 543, $str );
--- ปิดโค้ด ---


ค้นหาต่อที่คำว่า...

--- โค๊ด: ---if (setlocale(LC_TIME, $txt['lang_locale']))
  {
    foreach (array('%a', '%A', '%b', '%B') as $token)
      if (strpos($str, $token) !== false)
        $str = str_replace($token, $func['ucwords'](strftime($token, $time)), $str);
--- ปิดโค้ด ---

หรือถ้าด้านบนไม่มี ก็อันนี้

--- โค๊ด: ---if (setlocale(LC_TIME, $txt['lang_locale']))
{
if (!isset($non_twelve_hour))
$non_twelve_hour = trim(strftime('%p')) === '';
if ($non_twelve_hour && strpos($str, '%p') !== false)
$str = str_replace('%p', (strftime('%H', $time) < 12 ? $txt['time_am'] : $txt['time_pm']), $str);

foreach (array('%a', '%A', '%b', '%B') as $token)
if (strpos($str, $token) !== false)
$str = str_replace($token, !empty($txt['lang_capitalize_dates']) ? $smcFunc['ucwords'](strftime($token, $time)) : strftime($token, $time), $str);
--- ปิดโค้ด ---



แล้วเอาโค้ดนี้...วางต่อท้าย

--- โค๊ด: ---// Convert Common Era (C.E.) into Buddhist Era (B.E., aka Thai year)
        $str = str_replace('%y', (strftime('%y', $time)+543)%100, $str);
        $str = str_replace('%Y', strftime('%Y', $time)+543, $str);
--- ปิดโค้ด ---


แล้วเข้าไปปรับแต่งให้แสดงผลเป็นรูปแบบวันที่ตามที่เราต้องการ เช่น 14 มกราคม 2556 ,เวลา 20:48:57 น.
ผู้ดูแลระบบ -> ส่วนปรับแต่งค่าการใช้งาน -> รูปแบบเวลาปกติ %d %B %Y ,เวลา %H:%M:%S น.


หรือ
%d %b %Y, %H:%M:%S น.

ก็จะได้
07 ก.พ. 2560, 08:50:03 น.

*** หมายเหตุ ***
ในส่วนของการแสดง วัน เดือนปี ถ้าเราใส่อักษร เล็ก-ใหญ่ จะมีผลต่อการแดสงผลนะครับ เช่น
 %d  จะแสดงผลเป็นเช่น  03
 %D  จะแสดงผลเป็นเช่น  03/21/17
 %b  จะแสดงผลเป็นเช่น  มี.ค
 %B  จะแสดงผลเป็นเช่น  มีนาคม
 %y  จะแสดงผลเป็นเช่น  60
 %Y  จะแสดงผลเป็นเช่น  2560



ที่มา...
www.zone-it.com
www.question.in.th

นำร่อง

[0] ดัชนีข้อความ

ไปที่เวอร์ชันเต็ม
Powered by SMFPacks Social Login Mod