本文整理汇总了PHP中date_format_string函数的典型用法代码示例。如果您正苦于以下问题:PHP date_format_string函数的具体用法?PHP date_format_string怎么用?PHP date_format_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了date_format_string函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form_init_date_js
/**
* Initalize javascript for date type form element
*
* @staticvar bool $done make sure it gets initalize once.
* @global moodle_page $PAGE
*/
function form_init_date_js()
{
global $PAGE;
static $done = false;
if (!$done) {
$module = 'moodle-form-dateselector';
$function = 'M.form.dateselector.init_date_selectors';
$config = array(array('firstdayofweek' => get_string('firstdayofweek', 'langconfig'), 'mon' => date_format_string(strtotime("Monday"), '%a', 99), 'tue' => date_format_string(strtotime("Tuesday"), '%a', 99), 'wed' => date_format_string(strtotime("Wednesday"), '%a', 99), 'thu' => date_format_string(strtotime("Thursday"), '%a', 99), 'fri' => date_format_string(strtotime("Friday"), '%a', 99), 'sat' => date_format_string(strtotime("Saturday"), '%a', 99), 'sun' => date_format_string(strtotime("Sunday"), '%a', 99), 'january' => date_format_string(strtotime("January 1"), '%B', 99), 'february' => date_format_string(strtotime("February 1"), '%B', 99), 'march' => date_format_string(strtotime("March 1"), '%B', 99), 'april' => date_format_string(strtotime("April 1"), '%B', 99), 'may' => date_format_string(strtotime("May 1"), '%B', 99), 'june' => date_format_string(strtotime("June 1"), '%B', 99), 'july' => date_format_string(strtotime("July 1"), '%B', 99), 'august' => date_format_string(strtotime("August 1"), '%B', 99), 'september' => date_format_string(strtotime("September 1"), '%B', 99), 'october' => date_format_string(strtotime("October 1"), '%B', 99), 'november' => date_format_string(strtotime("November 1"), '%B', 99), 'december' => date_format_string(strtotime("December 1"), '%B', 99)));
$PAGE->requires->yui_module($module, $function, $config);
$done = true;
}
}
示例2: form_init_date_js
/**
* Initalize javascript for date type form element
*
* @staticvar bool $done make sure it gets initalize once.
* @global moodle_page $PAGE
*/
function form_init_date_js()
{
global $PAGE;
static $done = false;
if (!$done) {
$calendar = \core_calendar\type_factory::get_calendar_instance();
$module = 'moodle-form-dateselector';
$function = 'M.form.dateselector.init_date_selectors';
$defaulttimezone = date_default_timezone_get();
$config = array(array('firstdayofweek' => $calendar->get_starting_weekday(), 'mon' => date_format_string(strtotime("Monday"), '%a', $defaulttimezone), 'tue' => date_format_string(strtotime("Tuesday"), '%a', $defaulttimezone), 'wed' => date_format_string(strtotime("Wednesday"), '%a', $defaulttimezone), 'thu' => date_format_string(strtotime("Thursday"), '%a', $defaulttimezone), 'fri' => date_format_string(strtotime("Friday"), '%a', $defaulttimezone), 'sat' => date_format_string(strtotime("Saturday"), '%a', $defaulttimezone), 'sun' => date_format_string(strtotime("Sunday"), '%a', $defaulttimezone), 'january' => date_format_string(strtotime("January 1"), '%B', $defaulttimezone), 'february' => date_format_string(strtotime("February 1"), '%B', $defaulttimezone), 'march' => date_format_string(strtotime("March 1"), '%B', $defaulttimezone), 'april' => date_format_string(strtotime("April 1"), '%B', $defaulttimezone), 'may' => date_format_string(strtotime("May 1"), '%B', $defaulttimezone), 'june' => date_format_string(strtotime("June 1"), '%B', $defaulttimezone), 'july' => date_format_string(strtotime("July 1"), '%B', $defaulttimezone), 'august' => date_format_string(strtotime("August 1"), '%B', $defaulttimezone), 'september' => date_format_string(strtotime("September 1"), '%B', $defaulttimezone), 'october' => date_format_string(strtotime("October 1"), '%B', $defaulttimezone), 'november' => date_format_string(strtotime("November 1"), '%B', $defaulttimezone), 'december' => date_format_string(strtotime("December 1"), '%B', $defaulttimezone)));
$PAGE->requires->yui_module($module, $function, $config);
$done = true;
}
}
示例3: test_version1exportpathcreated
/**
* Test that the export path is created
*/
public function test_version1exportpathcreated()
{
global $CFG, $DB, $USER;
require_once $CFG->dirroot . '/local/datahub/fileplugins/log/log.class.php';
require_once $CFG->dirroot . '/local/datahub/lib.php';
set_config('export_path', 'exportpath/deeper', 'dhexport_version1');
$filepath = $CFG->dataroot . '/exportpath/deeper';
// Cleanup filepath if it exists at beginning of test.
if (file_exists($filepath)) {
rmdir($filepath);
}
// Set up the export file path.
$filename = 'rliptestexport.csv';
set_config('export_file', $filename, 'dhexport_version1');
// Set up data for one course and one enroled user.
$this->load_csv_data();
// Create a scheduled job.
$data = array('plugin' => 'dhexport_version1', 'period' => '5m', 'label' => 'bogus', 'type' => 'dhexport');
$taskid = rlip_schedule_add_job($data);
// Change the next runtime to a known value in the past.
$task = new stdClass();
$task->id = $taskid;
$task->nextruntime = 99;
$DB->update_record('local_eliscore_sched_tasks', $task);
$job = new stdClass();
$job->id = $DB->get_field(RLIP_SCHEDULE_TABLE, 'id', array('plugin' => 'dhexport_version1'));
$job->nextruntime = 99;
$DB->update_record(RLIP_SCHEDULE_TABLE, $job);
// Lower bound on starttime.
$starttime = time();
$datestr = date_format_string($starttime, '%b_%e_%Y_');
// not Windows compatible %e
$outputfilename = 'rliptestexport_' . $datestr . '*.csv';
// Wildcard for time
// Run the export.
$taskname = $DB->get_field('local_eliscore_sched_tasks', 'taskname', array('id' => $taskid));
run_ipjob($taskname);
// Debug code ...
/*
error_log("Export file name to test for: {$outputfilename}");
ob_start();
var_dump(glob($filepath.'/*'));
$tmp = ob_get_contents();
ob_end_clean();
error_log("Export files: {$tmp}");
*/
$files = glob($filepath . '/' . $outputfilename);
$exists = !empty($files);
// Cleanup the new file and folder.
if ($exists) {
unlink($files[0]);
rmdir($filepath);
}
$this->assertTrue($exists);
}
示例4: test_date_format_string
/**
* Test the function date_format_string().
*/
public function test_date_format_string()
{
global $CFG;
// Forcing locale and timezone.
$oldlocale = setlocale(LC_TIME, '0');
if ($CFG->ostype == 'WINDOWS') {
setlocale(LC_TIME, 'English_Australia.1252');
} else {
setlocale(LC_TIME, 'en_AU.UTF-8');
}
$systemdefaulttimezone = date_default_timezone_get();
date_default_timezone_set('Australia/Perth');
$tests = array(array('tz' => 99, 'str' => '%A, %d %B %Y, %I:%M %p', 'expected' => 'Saturday, 01 January 2011, 06:00 PM'), array('tz' => 0, 'str' => '%A, %d %B %Y, %I:%M %p', 'expected' => 'Saturday, 01 January 2011, 10:00 AM'), array('tz' => -12, 'str' => '%A, %d %B %Y, %I:%M %p', 'expected' => 'Saturday, 01 January 2011, 10:00 AM'), array('tz' => 99, 'str' => 'Žluťoučký koníček %A', 'expected' => 'Žluťoučký koníček Saturday'), array('tz' => 99, 'str' => '言語設定言語 %A', 'expected' => '言語設定言語 Saturday'), array('tz' => 99, 'str' => '简体中文简体 %A', 'expected' => '简体中文简体 Saturday'));
// Note: date_format_string() uses the timezone only to differenciate
// the server time from the UTC time. It does not modify the timestamp.
// Hence similar results for timezones <= 13.
// On different systems case of AM PM changes so compare case insensitive.
foreach ($tests as $test) {
$str = date_format_string(1293876000, $test['str'], $test['tz']);
$this->assertSame(core_text::strtolower($test['expected']), core_text::strtolower($str));
}
// Restore system default values.
date_default_timezone_set($systemdefaulttimezone);
setlocale(LC_TIME, $oldlocale);
}
示例5: test_date_format_string
/**
* Test the function date_format_string().
*/
public function test_date_format_string()
{
global $CFG;
$this->resetAfterTest();
$this->setTimezone(99, 'Australia/Perth');
$tests = array(array('tz' => 99, 'str' => '%A, %d %B %Y, %I:%M %p', 'expected' => 'Saturday, 01 January 2011, 06:00 PM'), array('tz' => 0, 'str' => '%A, %d %B %Y, %I:%M %p', 'expected' => 'Saturday, 01 January 2011, 10:00 AM'), array('tz' => 'Pacific/Auckland', 'str' => '%A, %d %B %Y, %I:%M %p', 'expected' => 'Saturday, 01 January 2011, 11:00 PM'), array('tz' => 99, 'str' => 'Žluťoučký koníček %A', 'expected' => 'Žluťoučký koníček Saturday'), array('tz' => 99, 'str' => '言語設定言語 %A', 'expected' => '言語設定言語 Saturday'), array('tz' => 99, 'str' => '简体中文简体 %A', 'expected' => '简体中文简体 Saturday'));
// Note: date_format_string() uses the timezone only to differenciate
// the server time from the UTC time. It does not modify the timestamp.
// Hence similar results for timezones <= 13.
// On different systems case of AM PM changes so compare case insensitive.
foreach ($tests as $test) {
$str = date_format_string(1293876000, $test['str'], $test['tz']);
$this->assertSame(core_text::strtolower($test['expected']), core_text::strtolower($str));
}
}
示例6: userdate
/**
* Returns a formatted string that represents a date in user time
*
* Returns a formatted string that represents a date in user time
* <b>WARNING: note that the format is for strftime(), not date().</b>
* Because of a bug in most Windows time libraries, we can't use
* the nicer %e, so we have to use %d which has leading zeroes.
* A lot of the fuss in the function is just getting rid of these leading
* zeroes as efficiently as possible.
*
* If parameter fixday = true (default), then take off leading
* zero from %d, else maintain it.
*
* @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)
{
global $CFG;
if (empty($format)) {
$format = get_string('strftimedaydatetime', 'langconfig');
}
if (!empty($CFG->nofixday)) {
// Config.php can force %d not to be fixed.
$fixday = false;
} else {
if ($fixday) {
$formatnoday = str_replace('%d', 'DD', $format);
$fixday = $formatnoday != $format;
$format = $formatnoday;
}
}
// Note: This logic about fixing 12-hour time to remove unnecessary leading
// zero is required because on Windows, PHP strftime function does not
// support the correct 'hour without leading zero' parameter (%l).
if (!empty($CFG->nofixhour)) {
// Config.php can force %I not to be fixed.
$fixhour = false;
} else {
if ($fixhour) {
$formatnohour = str_replace('%I', 'HH', $format);
$fixhour = $formatnohour != $format;
$format = $formatnohour;
}
}
//add daylight saving offset for string timezones only, as we can't get dst for
//float values. if timezone is 99 (user default timezone), then try update dst.
if (99 == $timezone || !is_numeric($timezone)) {
$date += dst_offset_on($date, $timezone);
}
$timezone = get_user_timezone_offset($timezone);
// If we are running under Windows convert to windows encoding and then back to UTF-8
// (because it's impossible to specify UTF-8 to fetch locale info in Win32)
if (abs($timezone) > 13) {
/// Server time
$datestring = date_format_string($date, $format, $timezone);
if ($fixday) {
$daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $date)));
$datestring = str_replace('DD', $daystring, $datestring);
}
if ($fixhour) {
$hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $date)));
$datestring = str_replace('HH', $hourstring, $datestring);
}
} else {
$date += (int) ($timezone * 3600);
$datestring = date_format_string($date, $format, $timezone);
if ($fixday) {
$daystring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %d', $date)));
$datestring = str_replace('DD', $daystring, $datestring);
}
if ($fixhour) {
$hourstring = ltrim(str_replace(array(' 0', ' '), '', gmstrftime(' %I', $date)));
$datestring = str_replace('HH', $hourstring, $datestring);
}
}
return $datestring;
}
示例7: timestamp_to_date_string
/**
* Returns a formatted string that represents a date in user time.
*
* Returns a formatted string that represents a date in user time
* <b>WARNING: note that the format is for strftime(), not date().</b>
* Because of a bug in most Windows time libraries, we can't use
* the nicer %e, so we have to use %d which has leading zeroes.
* A lot of the fuss in the function is just getting rid of these leading
* zeroes as efficiently as possible.
*
* If parameter fixday = true (default), then take off leading
* zero from %d, else maintain it.
*
* @param int $time the timestamp in UTC, as obtained from the database
* @param string $format strftime format
* @param int|float|string $timezone the timezone to use
* {@link http://docs.moodle.org/dev/Time_API#Timezone}
* @param bool $fixday if true then the leading zero from %d is removed,
* if false then the leading zero is maintained
* @param bool $fixhour if true then the leading zero from %I is removed,
* if false then the leading zero is maintained
* @return string the formatted date/time
*/
public function timestamp_to_date_string($time, $format, $timezone, $fixday, $fixhour)
{
global $CFG;
if (empty($format)) {
$format = get_string('strftimedaydatetime', 'langconfig');
}
if (!empty($CFG->nofixday)) {
// Config.php can force %d not to be fixed.
$fixday = false;
} else {
if ($fixday) {
$formatnoday = str_replace('%d', 'DD', $format);
$fixday = $formatnoday != $format;
$format = $formatnoday;
}
}
// Note: This logic about fixing 12-hour time to remove unnecessary leading
// zero is required because on Windows, PHP strftime function does not
// support the correct 'hour without leading zero' parameter (%l).
if (!empty($CFG->nofixhour)) {
// Config.php can force %I not to be fixed.
$fixhour = false;
} else {
if ($fixhour) {
$formatnohour = str_replace('%I', 'HH', $format);
$fixhour = $formatnohour != $format;
$format = $formatnohour;
}
}
$time = (int) $time;
// Moodle allows rubbish in input...
$datestring = date_format_string($time, $format, $timezone);
date_default_timezone_set(\core_date::get_user_timezone($timezone));
if ($fixday) {
$daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $time)));
$datestring = str_replace('DD', $daystring, $datestring);
}
if ($fixhour) {
$hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $time)));
$datestring = str_replace('HH', $hourstring, $datestring);
}
\core_date::set_default_server_timezone();
return $datestring;
}