|
|
 |
strftime (PHP 3, PHP 4, PHP 5) strftime -- Format a local time/date according to locale settings Descriptionstring strftime ( string format [, int timestamp] )
Returns a string formatted according to the given format string
using the given timestamp or the current
local time if no timestamp is given. Month and weekday names and
other language dependent strings respect the current locale set
with setlocale().
The following conversion specifiers are recognized in the format
string:
%a - abbreviated weekday name according to the current locale
%A - full weekday name according to the current locale
%b - abbreviated month name according to the current locale
%B - full month name according to the current locale
%c - preferred date and time representation for the current
locale
%C - century number (the year divided by 100 and truncated to
an integer, range 00 to 99)
%d - day of the month as a decimal number (range 01 to 31)
%D - same as %m/%d/%y
%e - day of the month as a decimal number, a single digit is
preceded by a space (range ' 1' to '31')
%g - like %G, but without the century.
%G - The 4-digit year corresponding to the ISO week number (see %V).
This has the same format and value as %Y, except that if the ISO week
number belongs to the previous or next year, that year is used
instead.
%h - same as %b
%H - hour as a decimal number using a 24-hour clock (range 00
to 23)
%I - hour as a decimal number using a 12-hour clock (range 01
to 12)
%j - day of the year as a decimal number (range 001 to 366)
%m - month as a decimal number (range 01 to 12)
%M - minute as a decimal number
%n - newline character
%p - either `am' or `pm' according to the given time value, or
the corresponding strings for the current locale
%r - time in a.m. and p.m. notation
%R - time in 24 hour notation
%S - second as a decimal number
%t - tab character
%T - current time, equal to %H:%M:%S
%u - weekday as a decimal number [1,7], with 1 representing
Monday
| Warning |
Sun Solaris seems to start with Sunday as 1
although ISO 9889:1999 (the current C standard) clearly
specifies that it should be Monday.
|
%U - week number of the current year as a decimal number,
starting with the first Sunday as the first day of the first
week
%V - The ISO 8601:1988 week number of the current year as a
decimal number, range 01 to 53, where week 1 is the first
week that has at least 4 days in the current year, and with
Monday as the first day of the week. (Use %G or %g for the year
component that corresponds to the week number for the specified
timestamp.)
%W - week number of the current year as a decimal number,
starting with the first Monday as the first day of the first
week
%w - day of the week as a decimal, Sunday being 0
%x - preferred date representation for the current locale
without the time
%X - preferred time representation for the current locale
without the date
%y - year as a decimal number without a century (range 00 to
99)
%Y - year as a decimal number including the century
%Z or %z - time zone or name or abbreviation
%% - a literal `%' character
Note:
Not all conversion specifiers may be supported by your C
library, in which case they will not be supported by PHP's
strftime(). Additionally, not all platforms
support negative timestamps, therefore your date range may
be limited to no earlier than the Unix epoch. This means that
e.g. %e, %T, %R and %D (there might be more) and dates prior to
Jan 1, 1970 will not work on Windows, some Linux
distributions, and a few other operating systems. For Windows systems a
complete overview of supported conversion specifiers can be found at this
MSDN website.
Example 1. strftime() locale examples |
<?php
setlocale(LC_TIME, "C");
echo strftime("%A");
setlocale(LC_TIME, "fi_FI");
echo strftime(" in Finnish is %A,");
setlocale(LC_TIME, "fr_FR");
echo strftime(" in French %A and");
setlocale(LC_TIME, "de_DE");
echo strftime(" in German %A.\n");
?>
|
|
This example works if you have the respective locales installed
in your system.
Note:
%G and %V, which are based on ISO 8601:1988 week numbers can
give unexpected (albeit correct) results if the numbering system
is not thoroughly understood. See %V above and example below.
Example 2. ISO 8601:1988 week number example |
<?php
echo "12/28/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y", strtotime("12/28/2002")) . "\n";
echo "12/30/2002 - %V,%G,%Y = " . strftime("%V,%G,%Y", strtotime("12/30/2002")) . "\n";
echo "1/3/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2003")) . "\n";
echo "1/10/2003 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/10/2003")) . "\n";
echo "12/23/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/23/2004")) . "\n";
echo "12/31/2004 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("12/31/2004")) . "\n";
echo "1/2/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/2/2005")) . "\n";
echo "1/3/2005 - %V,%G,%Y = " . strftime("%V,%G,%Y",strtotime("1/3/2005")) . "\n";
?>
|
|
See also setlocale(),
mktime(),
strptime(),
and the
Open Group specification of strftime().
User Contributed Notes
strftime
patrick at codeministry dot dk
20-Apr-2005 04:50
For freebsd user:
You can find the full list of your locale under /usr/share/locale.
For example da_DK.ISO8859-1 under this directory will set up the locale to danish.
bohac at smartcat dot cz
19-Mar-2005 12:36
i had to use the czech representation of time on unix machine, running debian and linux version of apache with php 4
for me the best solution was to use this code:
<php
setlocale(LC_ALL, 'cs_CZ.iso88592');
?>
then you can do everything in czech language with correct iso-8859-2 encoding ;D
mflaig at pro-linux dot de
21-Feb-2005 05:57
Hi there,
i had the problem that I needed all days of an week with some extra infos. given is day, month, year (selectboxes).
so I hacked this together ...
function ...
<?php
function get_weekdates($year, $month, $day){
setlocale(LC_ALL, "C");
$searchdate = mktime(0,0,0,$month,$day,$year);
$day_of_week = strftime("%u", $searchdate);
$days_to_firstday = ($day_of_week - 1); $days_to_lastday = (7 - $day_of_week); $date_firstday = strtotime("-".$days_to_firstday." days", $searchdate);
$date_lastday = strtotime("+".$days_to_lastday. " days", $searchdate);
$d_result = ""; for($i=0; $i<=6; $i++) {
$y = $i + 1;
$d_date = strtotime("+".$i." days", $date_firstday);
$result[$y]['year'] = strftime("%Y", $d_date);
$result[$y]['month'] = strftime("%m", $d_date);
$result[$y]['day'] = strftime("%d", $d_date);
$result[$y]['dayname'] = strftime("%A", $d_date);
$result[$y]['shortdayname'] = strftime("%a", $d_date);
$result[$y]['sqldate'] = strftime("%Y-%m-%d", $d_date);
}
return $result; }
?>
so you can read all this by doing something like that:
<?php
$week = get_weekdates($year,$month,$day);
for($i = 1; $i<=7 ; $i++) {
echo 'Year: ' . $week[$i]['year'] . '<br>';
echo 'Month: ' . $week[$i]['month'] . '<br>';
echo 'Day: ' . $week[$i]['day'] . '<br>';
echo 'Longname: ' . $week[$i]['dayname'] . '<br>';
echo 'Shortname: ' . $week[$i]['shortdayname'] . '<br>';
echo 'Sqldate: ' . $week[$i]['sqldate'] . '<br>';
echo '<br>';
}
?>
I hope this helpes someone out there ...
... notes and improvements welcome (via email / pgp preferred)
Note: It does not work on Slowlaris <8 because of the %u problem (see the other posting for further details)
for Windows and solaris you may check out the posting of vesa dot kivisto at nepton dot fi ....
this code was inspired by pb at _remove_ pedal dot dk ´s code
Have a nice day (night || whatever),
mfl
Aaron
25-Jan-2005 03:10
%k will give you %H (hour, 24-hour clock) with the leading zero replaced by a space. I have only tested this on one linux system so far, it may not work on windows or other linux builds.
james at oicgroup dot net
19-Nov-2004 09:27
In looking for a way to trim the leading zero from a 12 hour time format (08:30 PM for instance), we happened upon %l (lowercase L) quite by accident. It replaces the leading zero with a space similiar to what %e does with dates, so you get 8:30 PM instead of 08:30 PM.
michiel1978 at hotmail dot com
06-Oct-2004 04:31
As said in these comments, Windows strftime() doesn't support %e. However, to achieve a similar effect (not 100%) you can use %#d. The # flag will remove the leading zero, so you do get single digits, but without the space that would be added by %e in other environments.
neo at gothic-chat d0t de
25-Jun-2004 01:27
To get a RFC 850 date (used in HTTP) of the current time:
gmstrftime ("%A %d-%b-%y %T %Z", time ());
This will get for example:
Friday 25-Jun-04 03:30:23 GMT
Please note that times in HTTP-headers _must_ be GMT, so use gmstrftime() instead of strftime().
bigfoot at spido dot dk
16-Jun-2004 08:12
The %e "bug" in strftime on Windows systems can be fixed this way...
<?
setlocale(LC_TIME, 'da');
$var1 = strftime("%A den ");
function strftime_e_fix(){
$var = strftime("%d");
if($var{0} == 0){$var = $var{1};}
return($var);
}
$var1 .= strftime_e_fix();
$var1 .= strftime(". %B, %Y");
echo $var1;
?>
adan at cr72 dot com
09-Jun-2004 06:48
For Spanish:
<?
setlocale(LC_ALL, "sp");
echo strftime("%d. %B %Y");
?>
verhoeff
15-Apr-2004 05:54
The locale for dutch on a win2k computer is not "nl_NL"
but "dutch".
php_manual at it-rex dot nl
28-Mar-2004 07:31
In the strftime override-function of rickenmeer at hotmail dot com there is an error.
The line:
$year = 1969;
should read:
$year = 1970;
rolex
25-Mar-2004 10:37
Searching for translation from IBASE-Timestamp to EU-Dateformat DD.MM.YYYY
strftime("%d.%m.%Y",strtotime($row->START_TIMESTAMP));
Maybe it's useful for somebody ;-)
pb at _remove_ pedal dot dk
22-Feb-2004 09:51
Ever wanted to find the first and last dates in a given week? i.e. you have a week number and a year, what date has the first and last days in that week respectively? Below is a function that does just that. You feed it with a week/year and it returns an array with first and last day:
function mk_week_to_dates($week, $year){
//We start some time into prev year
$searchdate = mktime(0,0,0,12,20,$year-1);
//Then we advance $week-1 weeks ahead (no need to search through dates we know won't give results)
$searchdate = strtotime("+".($week-1)." week",$searchdate);
$found=false;
while ($found==false){
if (date("W",$searchdate) == $week)
$found = true;
else
$searchdate = strtotime("+1 day",$searchdate);
}
$weekdates['firstday'] = $searchdate;
$weekdates['lastday'] = strtotime("+6 day",$searchdate);
return $weekdates;
}
rickenmeer at hotmail dot com
12-Jan-2004 10:10
This override for strftime was created to cope with the date limits on Win32 (1970-2037). Current mappings and allows you to calculate daylight savings time etc. for 1902-1969, feel free to add more mappings!
<?PHP
function &strftime ($format = "", $timestamp = false)
{
if ($timestamp >= 0 && $timestamp <= 2147480047)
{ return strftime ($format, $timestamp);
}
$mappings = Array (
Array ("start" => 1902, "end" => 1951, "map" => 1986), Array ("start" => 1952, "end" => 1969, "map" => 1980), );
if ($timestamp < 0)
{
$year = 1969;
while ($timestamp < 0)
{
$days = ($year % 4 == 0 && ($year % 100 > 0 || $year % 400 == 0)) ? 366 : 365;
$timestamp += $days * 86400;
$year--;
}
}
else {
$year = 2038;
while ($timestamp > 0)
{
$days = ($year % 4 == 0 && ($year % 100 > 0 || $year % 400 == 0)) ? 366 : 365;
$timestamp -= $days * 86400;
$year++;
}
}
foreach ($mappings as $mapping)
if ($year >= $mapping["start"] && $year <= $mapping["end"])
{
$find = Array ("%y", "%Y", "%D");
$replace = Array (substr ($year, -2), $year, "%m/%d/" . substr ($year, -2));
$format =& str_replace ($find, $replace, $format);
$map_from_1970 = mktime (0, 0, 0, 1, 1, $mapping["map"]);
return strftime ($format, $timestamp + $map_from_1970);
}
return "strftime (): Year not mapped yet: " . $year;
}
?>
vesa dot kivisto at nepton dot fi
01-Jan-2004 08:07
Windows users cannot use the %V specifier for strftime as it is not implemented in the OS.
Following is a possible workaround function to get the ISO 8601:1988 weeknumber.
Note that unlike the previous (20-Jan-2002) function, this function will also fix last week of the year to 01 whenever necessary.
<?php
function getWeekNumber($day, $month, $year) {
$week = strftime("%W", mktime(0, 0, 0, $month, $day, $year));
$yearBeginWeekDay = strftime("%w", mktime(0, 0, 0, 1, 1, $year));
$yearEndWeekDay = strftime("%w", mktime(0, 0, 0, 12, 31, $year));
if($yearBeginWeekDay > 0 && $yearBeginWeekDay < 5) {
$week++;
} else if($week == 0) {
$week = 53;
}
if($week == 53 && $yearEndWeekDay > 0 && $yearEndWeekDay < 5) {
$week = 1;
}
return( substr('0'. $week, -2) );
}
?>
John Baxendale
15-Oct-2003 07:15
Note that on Linux kernels before 2.4.* the date functions in PHP will happily accept a date before 01-01-1970 as stated at the top of this man page, post kernel 2.4.* the date functions *do not* work with dates before 1970.
If you've existing scripts doing date validation on dates before 1970, check them before you upgrade your kernel!
**
Editor's note: This is actually a libc problem, and not a Kernel problem.
-seanATphpDOTnet
**
rchavezc at ameritech dot net
15-Jun-2003 01:03
The description of strtotime says that it can "Parse about any English textual datetime description into a UNIX timestamp". Be careful, however, when using "plain English". I was puzzled over why strtotime("June 23, 2003 at 12:00PM") returned a timestamp corresponding to 9:00 AM Central Time, until I realized the "at" was being interpreted as Azores Time or GMT+002. Writing strtotime("June 23, 2003 12:00PM") returned the correct timestamp.
Rafael
php dot net at frosch dot org
29-Apr-2003 06:06
Note to the comment from 'darianlassan at yahoo dot de':
Given a 'bare number' in seconds, e.g. 143567, strftime() will format this number ACCORDING TO YOUR LOCAL TIMEZONE. Thus, for Germany (where you probably are, since you have a .de address) you will get an extra hour, since CET is GMT +1.
If you are interested in simply formatting a number to give you hours, minutes and seconds (very quick for showing time values), then you should ALWAYS use 'gmstrftime' instead, which will not adjust the time for your local timezone.
Example: I have the decimal value 1.76 minutes returned to me by an application, and want to show this as MM:SS:
# time value comes as minute value in decimal
$time = 1.76;
# convert to seconds
$min = floor($time);
$sec = round((($time - $min) * 60));
$time_value = ($min * 60) + $sec;
# format using gmstrftime()
$fmt_time = gmstrftime("%M:%S",$time_value);
# display
echo "Time in minutes:seconds = $fmt_time";
cheers,
Nalfy.
luismorales at juntos dot com
10-Apr-2003 10:29
The next script print the week and day begin and end of the week
<?
$duracion = 12;
$dia = '05';
$mes = '03';
$anio = '2003';
$fecha_inicio = mktime(0,0,0,$mes,$dia,$anio);
$semana_inicio = strftime("%W", mktime(0,0,0,$mes,$dia,$anio));
$dia_semana_inicio =strftime("%u", mktime(0,0,0,$mes,$dia,$anio));
echo "Fecha Inicio :: {$dia}/{$mes}/{$anio}<br>";
echo "semana :: {$semana_inicio} <br>";
echo "Dia Semana Inicio :: {$dia_semana_inicio} <br>";
$x_ini = ($dia_semana_inicio > 1) ? ($fecha_inicio - ($dia_semana_inicio-1)* 86400) : ($fecha_inicio) ;
for($i=0;$i<=$duracion;$i++){
$y_ini = (int) $x_ini + ($i*7*86400);
$y_fin = (int) $x_fin + ($i*7*86400);
echo "Semana :: ".strftime("%V", mktime(0,0,0,date("m", $y_ini), date("d", $y_ini), date("Y", $y_ini) )) . " :: [ " . date("d-m-Y", $y_ini) ."/" .date("d-m-Y", $y_fin)." ]<br>";
}
?>
shaun at nospam dot phplabs dot com
14-Mar-2003 06:03
I recently needed a way to find the first second of the current week. The catch was that strftime("%u") considers Monday as the first day of the week, whereas I needed things based on Sundays.
My solution was to determine how many days had elapsed since the previous Sunday (0 if today is a Sunday), and subtract that may days from the current day's midnight timestamp:
$weekstart = mktime(0, 0, 0, date("m"), date("d"), date("Y")) - ((strftime("%u") == 7) ? 0 : (86400 * strftime("%u")));
This will assign the epoch stamp of the most recent Sunday at 00:00 (today at 00:00, if today is a Sunday) to $weekstart.
pb at pedal dot dk
21-Dec-2002 10:37
I am truly sorry - I contributed with a script to overcome the missing %V for Windows-users. It contained a serious flaw, that prohibited in some cases. Below is a script, that should work in all cases. I have tested it on most outer cases, e.g. 2005/12/31 and 2006/01/01.
function ISOWeek($y, $m, $d)
{
$week=strftime("%W", mktime(0, 0, 0, $m, $d, $y));
$dow0101=getdate(mktime(0, 0, 0, 1, 1, $y));
$next0101=getdate(mktime(0, 0, 0, 1, 1, $y+1));
if ($dow0101["wday"]>1 &&
$dow0101["wday"]<5)
$week++;
if ($next0101["wday"]>1 &&
$next0101["wday"]<5 &&
$week==53)
$week=1;
if ($week==0)
$week = ISOWeek($y-1,12,31);
return(substr("00" . $week, -2));
}
Regards
fmj at no-spam dot r0x
04-Dec-2002 09:26
setlocale(LC_ALL, "de_DE");
strftime("%d. %B %Y");
It could be that it doesn't work. Try "ge" instead of "de_DE".
setlocale(LC_ALL, "ge");
strftime("%d. %B %Y");
That will return "04. Dezember 2002"
newbie at hotmail dot com
02-Dec-2002 08:28
The provided example is very bad for newbies. Why does setlocale with "C" print out a date in english? Why is this not even documented on the setlocale page? Why is the example text inserted into the strftime function? Such hacks are a sure way to confuse a lot of people.
Examples should be as simple as possible. Remember that people are here because they don't know everything but would like to know.
So if you are a newbie like me, here is the same example, formatted differently, so that you may understand it more easily:
echo "The current time with your standard settings is: ";
setlocale (LC_TIME, "C");
// C stands for "standard settings"
echo strftime ("%A");
echo " in finnish: ";
setlocale (LC_TIME, "fi_FI");
echo strftime ("%A");
echo " in french: ";
setlocale (LC_TIME, "fr_FR");
echo strftime ("%A");
echo " in german: ";
setlocale (LC_TIME, "de_DE");
echo strftime ("%A");
jdavid at NO_SPAM dot skynet dot be
19-Nov-2002 05:47
If you are using MySQL database timestamps and you wish
to display for example the time and date represented by such
a timestamp, you can use the following function:
function DateAndTime ($timestamp)
{
list($year,$month,$day,$hour,$minute,$second) =
sscanf($timestamp,"%4s%2s%2s%2s%2s%2s");
setlocale("LC_TIME","nl_BE.ISO8859-15@euro");
return strftime("%c",
mktime($hour,$minute,$second,
$month,$day,$year));
}
This function will return the correct date and time in the
locale of your choice, in the default representation.
example:
----------
list($timestamp,$dummy1, ..) = mysql_fetch_row($result);
$displaytime = DateAndTime($timestamp);
echo "The date and time is: $displaytime";
I hope you find this usefull ..
mbostrom at paragee dot com
14-Nov-2002 03:31
If you are building a web app that will be used by people different timezones from the server on which the app is running, you can switch the timezone on the fly by doing the following before calling strftime (), or the other timestamp processing functions.
This is very easy if you know how to do it. If you don't you'll spend hours trying to manually slide timestamps around.
putenv ("TZ=PST8PDT");
print strftime ("%T %Z");
putenv ("TZ=EST5EDT");
print strftime ("%T %Z");
Valid timezone codes can (usually) be seen (on Linux, at least) in /usr/share/zoneinfo or /usr/lib/zoneinfo (according to the tzset manpage).
kaldari at monsterlabs dot com
31-Oct-2002 05:38
Actaully, %p returns 'AM' or 'PM', not 'am' or 'pm'.
matt at crx4u dot com
30-Oct-2002 08:53
Here's a pair of functions to convert a date to an ISO 8601 year/week and vice versa.
function yearweek($date="") {
if (!$date) $date = mktime();
$yearweek = strftime("%G%V", $date);
return $yearweek;
}
function dateEndYearweek($yearweek) {
$weekEndDay = 0; // 0 = Sunday.
$year = (int) substr($yearweek, 0, 4);
$week = (int) substr($yearweek, -2, 2);
// We know that the 4th Jan is always in week 01, 11th Jan in week 02, ...
// so day (4 + (w-1)*7) is in week w.
$dayOfYear = 4 + (($week - 1) * 7);
$date = mktime(0, 0, 0, 1, $dayOfYear, $year);
// Find the last day of this week.
$dayOfWeek = date("w", $date);
$daysToAdd = ($weekEndDay - $dayOfWeek + 7) % 7;
$date += $daysToAdd * 24*60*60;
return $date;
}
Janos dot Zana at elfiz2 dot kee dot hu
21-Oct-2002 01:10
To write the data of a mySQL data base
I suppose: setlocale (LC_TIME, "hu_HU");
$filemod = filemtime("/var/lib/mysql/somewhere/table_name.ISM");
$filemodtime = date("Y F j H:i:s T", $filemod);
echo strftime('%Y %B %d %A %H óra %M perc', $filemod);
E.g. in Hungarian
yedidia at yedidia dot net
09-Oct-2002 04:32
I used it with Hebrew in this way:
setlocale(LC_TIME, "he");
echo strftime("%A - %e %B %Y",$timestamp);
jhorvath at bcn dot hu
27-Aug-2002 02:22
Under Windows the %W works wrong: it gives 1 for 2001.01.01 instead of 0! Be careful with strftime under Windows.
vanessa at val dot it
09-Jun-2002 12:21
//I needed the $end_date for an interval of $nights with a set $date_begin, in format 2002-06-01. it took me a long time to work this out for whom it could be usefull
$date_begin = explode("-", $date);//$date is the date the user entered
list($year, $month, $day) = $date_begin;
$end_date = strftime("%Y-%m-%d", mktime(0,0,0,$month,$day+$nights,$year));//$nights being the interval
echo "begin date $date_begin to $end_date";
gregory at justretail dot com
27-May-2002 03:09
Using a class to format a date.
This example shows how to format a date using a timestamp. You can obtain the timestamp through your MySQL Select statement, e.g, SELECT UNIX_TIMESTAMP(date_field) as my_timestamp FROM table, or by using strtotime, e.g., $my_timestamp = strtotime (date_field).
// This class expects a date array value and returns a formatted date. You can add additional methods to return different date formats--obviously!
<?php
class DateMake {
var $month;
var $day;
var $year;
function DateMake($ts="") {
$date_time_array = $ts;
$this->month = $date_time_array["mon"];
$this->day = $date_time_array["mday"];
$this->year = $date_time_array["year"];
return ($this->month."/".$this->day."/".$this->year);
}
function Month() {
return $this->month;
}
function Day() {
return $this->day;
}
function Year() {
return $this->year;
}
}
?>
// Add the "require_once" reference
to each php page which needs to use this class.
require_once("class.DateMake.php");
// instantiate the class
$oDateMake = new DateMake();
// call the method. The timestamp is passed to getdate(), (you can also pass an empty getdate() to the class to return the current date).
$myDate = $oDateMake->DateMake(getdate($myresult['my_timestamp']));
You can modify this class or create your own date formatting class; whichever you choose, the important thing to note about classes is that they can replace in-line data formatting code in your php pages with re-usable polymorphic code.
kemps at free dot fr
06-May-2002 07:33
Using strftime() with a negative Unix Timestamp doesn't seem to work.
I'm trying to format a birthdate before 1 January 1970.
...
$time= mktime(0,0,0,$birthmonth,$birthday,$birthyear);
return strftime("%e ",$time) . ucfirst(strftime("%B ",$time)) . strftime("%Y ",$time);
}
the returned string is a blank string everytime my $time is a negative timestamp.
wils at mac dot com
03-Apr-2002 02:22
To get Swedish this works on win32 (w2k)
<?php
setlocale (LC_ALL, "");
print (strftime ("%A den %e %B %Y"));
?>
%e does, however, not work.
arnaud at cenet dot fr
10-Jan-2002 01:43
I saw issues with locale settings...
this one works on php-apache-windows and cobalt-apache servers :
setlocale ("LC_TIME","french");
rather than "fr"...
mats dot lindblad at it dot su dot se
10-Jan-2002 05:58
It seems that the %W doesn't work for 2002, it says that this week is week 1 and that's not correct.
I have no code to correct this yet but I guess that it will have to suffise to ++ it for now!
joakim at gissberg dot nu
02-Oct-2001 01:40
All system doesn't have all LC_* information, my Slackware 8 didn't have LC_TIME for example.
I made them (swedish example) using 'localedef -f ISO-8859-1 -i sv_SE sv' in /usr/share/locale.
mfischer at nospam-guru dot josefine dot at
14-Sep-2001 08:29
vminarik at ips-ag dot cz
10-Sep-2001 08:02
Note that setting LC_TIME is not enough for some locales under Windows, e.g. Czech, because there are some characters not contained in default (US) character set like 'č' (c with hook), 'ř' (r with hook).
If you run Apache as regular application and have set your locale to Czech (ControlPanel/RegionalOptions), there is no problem and 'September' is correctly translated as 'září', 'Thursday' as 'čtvrtek'.
But if you run Apache as service, you get 'zárí', and 'ctvrtek'.
To get things work as you expect you must set LC_CTYPE beside LC_TIME, or set LC_ALL.
<?
$locale = 'Czech_Czech.1250';
$res = setlocale( 'LC_CTYPE', $locale); $res = setlocale( 'LC_TIME', $locale);
echo strftime( '%A %m. %B %Y', mktime( 0,0,0,9,6,2001));
?>
verdy_p at wanadoo dot fr
22-Jul-2001 07:33
Beware of '%D':
the comment shown expects that this is the same as '%m/%d/%y'.
This is wrong: '%D' is only expected to returned an abbreviated numeric date according to the current locale:
In the German locale '%D' is '%y.%m.%d'
In the French locale '%D' is '%d/%m/%y'
The locale rules still apply to %D as with '%A'...
Beware that some C libraries do not support '%D' and/or '%A' or do not support them accordingly. Using strftime() is then system-dependant, because PHP use the C function provided by the system on which it runs.
spamyenot at example dot com
18-Jul-2001 01:09
Solaris 2.6 and 7 define the
%u specifier differently than noted here. Day 1 is Sunday, not Monday. Solaris 8 gets it right.
Jim
master at px dot pl
03-Jun-2001 12:49
there's a tricky way to print all weekdays in local language e.g.:
<?
setlocale("LC_TIME", "pl_PL");
for($i=0;$i<=6;$i++) { print(strftime("%A",mktime(0,0,0,2,$i,0))."\n"); }
?>
enjoy it :)
Master
darianlassan at yahoo dot de
09-Apr-2001 08:17
Be careful by using strftime() to display a period in seconds userfriendly. strftime("%H",3600) will return "02" but the period is one hour. So subtract 3600 to get it right.
zmajeed at cup dot hp dot com
22-Jul-1999 05:14
Locale names are OS dependent. HP-UX 11.0, for example, has three
German locales, de_DE.roman8, de_DE.iso88591, and
de_DE.iso885915@euro.
The command locale -a will display all available locales on a system.
So on HP-UX, to get German dates:
setlocale("LC_TIME", "de_DE.roman8");
print(strftime("%A\n"));
| |