Drupal : เทคนิคการจัด Format date time ใน Drupal ในการแสดงผล
200925 May
เทคนิคการจัด Format date time ใน Drupal ในการแสดงผล
ให้นำ javascript ด้านล่างนี้ไปวางใน template.php เพื่อใช้เรียกประกาศการใช้ function format_timestamp_to_drupal_date
อันนี้เพิ่มเติม function สร้าง time stamp ขึ้นมาเองน่ะคับลองนำไปใช้กันเพื่อจำเป็น
function format_timestamp_to_drupal_date($timestamp) {
$day = format_date($timestamp, 'custom', d);
$month = format_date($timestamp, 'custom', n);
$year = format_date($timestamp, 'custom', Y);
return array('day'=> $day,'month'=>$month,'year'=>$year);
}
$day = format_date($timestamp, 'custom', d);
$month = format_date($timestamp, 'custom', n);
$year = format_date($timestamp, 'custom', Y);
return array('day'=> $day,'month'=>$month,'year'=>$year);
}
นำ function ส่วนนี้มาใช้หรืออะไรก้อตามที่ return เป็นค่า timestamp แต่ที่ผมใช้้จะใช้ในส่วน node.tpl.php หรือ node.page.tpl.php หรืออื่น ๆ ที่คุณต้องการจัดการกับ timestamp ในกรณีผมต้องการแก้ไข $node->created คือ วันที่เราสร้าง node ให้มี Format ที่เราต้องการ เราสามารถนำค่าจาก return ออกมาเป็นตัวแปรที่ต้องการใช้ได้เช่น $cdate['year'] , $cdate['month'] , $cdate['day']; ึคุณสามารถดัดแปลงให้แสดงวันที่แบบไทยก้อ ได้น่ะคับก้อลองไปประยุกต์ต่อน่ะคับ ....
<? $cdate=format_timestamp_to_drupal_date($node->created); ?>
<div class="calendar"><p><?=$cdate['year'];?><span><?=$cdate['day'];?> <?=$cdate['month'];?></span></p>
</div>
<div class="calendar"><p><?=$cdate['year'];?><span><?=$cdate['day'];?> <?=$cdate['month'];?></span></p>
</div>
function format_timestamp($date = 1) {
return mktime(0,0,0,$date['month'],$date['day'],$date['year']) + 36000;
}
return mktime(0,0,0,$date['month'],$date['day'],$date['year']) + 36000;
}