function date_i18n($dateformatstring, $unixtimestamp) { $i = $unixtimestamp; $month = get_month_names('long'); $month_abbrev = get_month_names('short'); $weekday = get_day_names('long'); $weekday_abbrev = get_day_names('short'); if (!empty($month) && !empty($weekday)) { $datemonth = $month[intVal(date('m', $i))]; $datemonth_abbrev = $month_abbrev[intVal(date('m', $i))]; $dateweekday = $weekday[intVal(date('w', $i))]; $dateweekday_abbrev = $weekday_abbrev[intVal(date('m', $i))]; $dateformatstring = ' ' . $dateformatstring; $dateformatstring = preg_replace("/([^\\\\])D/", "\\1" . backslashit($dateweekday_abbrev), $dateformatstring); $dateformatstring = preg_replace("/([^\\\\])F/", "\\1" . backslashit($datemonth), $dateformatstring); $dateformatstring = preg_replace("/([^\\\\])l/", "\\1" . backslashit($dateweekday), $dateformatstring); $dateformatstring = preg_replace("/([^\\\\])M/", "\\1" . backslashit($datemonth_abbrev), $dateformatstring); $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring) - 1); } $j = @date($dateformatstring, $i); return $j; }
<?php if (!extension_loaded('rarray')) { dl('rarray.dll'); } $ar = get_month_names(); for ($i = 0; $i < 12; $i++) { $x = $i + 1; echo sprintf("%02d : ", $x); print "{$ar[$i]}\n"; } $ar2 = get_year_info(); $months = $ar2["months"]; $smonths = $ar2["abbrevmonths"]; echo "\n"; for ($i = 0; $i < 12; $i++) { $x = $i + 1; echo sprintf("%02d : ", $x); echo sprintf("%12s : ", $months[$i]); print "{$smonths[$i]}\n"; } ?>
/** * @author Robert Doucette * @param string $name * @param int $year * @return obj * @version 0.5 */ function get_month_info($name, $year) { $year_before = $year; $year_after = $year; switch($name) { case 'janvier': $year_before = $year-1;break; case 'décembre': $year_after = $year+1; } $names = get_month_names(); $cur = (array_key_exists($name, $names)) ? $names[$name]['num'] : 9; //showing the month of september during july and august $before = $cur-1; $after = $cur+1; switch($cur) { case 1: $before = 12;break; case 12: $after = 1; } $day_num = 1; $day_num_before = cal_days_in_month(0, $before, $year_before); $days_in_month = cal_days_in_month(0, $cur, $year); $first_day = mktime(0,0,0,$cur,1,$year); $month_start = strftime('%a', $first_day); switch($month_start) { case 'mar.':$day_num=0;break; case 'mer.':$day_num=-1;$day_num_before=$day_num_before-1;break; case 'jeu.':$day_num=-2;$day_num_before=$day_num_before-2;break; case 'ven.':$day_num=-3;$day_num_before=$day_num_before-3;break; case 'sam.':$day_num=3;break; case 'dim.':$day_num=2; } foreach($names as $key=>$value) { switch($value['num']) { case $before == 8 ? 6 : $before: $before_long = $value['name_long']; $before_short = $value['name_short']; $before_accent = $key; break; case $cur: $long = $value['name_long']; $short = $value['name_short']; $accent = $key; break; case $after == 7 ? 9 : $after: $after_long = $value['name_long']; $after_short = $value['name_short']; $after_accent = $key; } } return (object) array( 'month' => (object) array( 'before' => $before, 'cur' => $cur, 'after' => $after ), 'year' => (object) array( 'before' => $year_before, 'cur' => $year, 'after' => $year_after ), 'day' => (object) array( 'before' => $day_num_before, 'cur' => $day_num, 'after' => 1 ), 'name' => (object) array( 'before' => (object) array( 'long' => $before_long, 'short' => $before_short, 'accent' => $before_accent ), 'cur' => (object) array( 'long' => $long, 'short' => $short, 'accent' => $accent ), 'after' => (object) array( 'long' => $after_long, 'short' => $after_short, 'accent' => $after_accent ) ), 'days_in_month' => $days_in_month, ); }
/** * Returns a <select> tag populated with all the months of the year (1 - 12). * * By default, the <i>$value</i> parameter is set to today's month. To override this, simply pass an integer * (1 - 12) to the <i>$value</i> parameter. You can also set the <i>$value</i> parameter to null which will disable * the <i>$value</i>, however this will only be useful if you pass 'include_blank' or 'include_custom' to the <i>$options</i> * parameter. Also, the each month's display title is set to return its respective full month name, which can be easily * overridden by passing the 'use_short_names' or 'use_month_numbers' options to the <i>$options</i> parameter. * For convenience, Symfony also offers the select_date_tag helper function which combines the * select_year_tag, select_month_tag, and select_day_tag functions into a single helper. * * <b>Options:</b> * - include_blank - Includes a blank <option> tag at the beginning of the string with an empty value * - include_custom - Includes an <option> tag with a custom display title at the beginning of the string with an empty value * - use_month_numbers - If set to true, will show the month's numerical value (1 - 12) instead of the months full name. * - use_short_month - If set to true, will show the month's short name (i.e. Jan, Feb, Mar) instead of its full name. * - add_month_numbers - If set to true, will show the month's name and numerical value (i.e. "Jan - 1", "Dec - 12") * * <b>Examples:</b> * <code> * echo submit_month_tag('month', 5, array('use_short_month' => true)); * </code> * * <code> * echo submit_month_tag('month', null, array('use_month_numbers' => true, 'include_blank' => true)); * </code> * * @param string field name * @param integer selected value (1 - 12) * @param array additional HTML compliant <select> tag parameters * @return string <select> tag populated with all the months of the year (1 - 12). * @see select_date_tag, select datetime_tag */ function select_month_tag($name, $value = null, $options = array(), $html_options = array()) { if ($value === null) { $value = date('n'); } $options = _parse_attributes($options); $select_options = array(); if (_get_option($options, 'include_blank')) { $select_options[''] = ''; } else { if ($include_custom = _get_option($options, 'include_custom')) { $select_options[''] = $include_custom; } } if (_get_option($options, 'use_month_numbers')) { for ($k = 1; $k < 13; $k++) { $select_options[$k] = _prepend_zeros($k, 2); } } else { if (_get_option($options, 'use_short_month')) { $month_names = get_month_names('short'); } else { $month_names = get_month_names(); } $add_month_numbers = _get_option($options, 'add_month_numbers'); foreach ($month_names as $k => $v) { $select_options[$k] = $add_month_numbers ? $k . ' - ' . $v : $v; } } return select_tag($name, options_for_select($select_options, $value), $html_options); }