「全部點名紀錄列表」日期欄中的「日」如小於10則前面補0

JDP 2018-11-6 551

修改 /mod/attendance/renderer.php

原始

private function construct_date_time_actions(attendance_manage_data $sessdata, $sess) {
...
   $date = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'));
...
}

修改後

private function construct_date_time_actions(attendance_manage_data $sessdata, $sess) {
...
   $date = userdate($sess->sessdate, get_string('strftimedmyw', 'attendance'),99,false);
...
}



Moodle預設會將所有顯示 %d 的「前方補0 (leading zeros)」修改為不補0,主要可藉由 /lib/moodlelib.php 定義的 userdate Function中的 $fixday 參數進行調整,如果 $fixday = false 就會補 0 了!

/**
 * Returns a formatted string that represents a date in user time.
 *
 * @package core
 * @category time
 * @param int $date the timestamp in UTC, as obtained from the database.
 * @param string $format strftime format. You should probably get this using
 *        get_string('strftime...', 'langconfig');
 * @param int|float|string $timezone by default, uses the user's time zone. if numeric and
 *        not 99 then daylight saving will not be added.
 *        {@link http://docs.moodle.org/dev/Time_API#Timezone}
 * @param bool $fixday If true (default) then the leading zero from %d is removed.
 *        If false then the leading zero is maintained.
 * @param bool $fixhour If true (default) then the leading zero from %I is removed.
 * @return string the formatted date/time.
 */
function userdate($date, $format = '', $timezone = 99, $fixday = true, $fixhour = true) {
    $calendartype = \core_calendar\type_factory::get_calendar_instance();
    return $calendartype->timestamp_to_date_string($date, $format, $timezone, $fixday, $fixhour);
}



最新回復 (0)
返回
發新帖