Tutorial created by Rune Brynestad, Totalweb AS
How to display date and time in your own language format using setlocale() and strftime().
The setlocale() function sets locale information.
Locale information is language, monetary, time and other information specific for a geographical area.
Note: The setlocale() function changes the locale only for the current script.
Find your Language and Locale code: http://red-route.org/code/php-international-language-and-locale-codes-demonstration
The strftime() function formats a local time and/or date according to locale settings.
See http://www.php.net/manual/en/function.strftime.php for more information
You need to use setlocale() and strftime(). If you use the setlocale function properly, the strftime function will give you the result in your own language.
<?php setlocale (LC_TIME, "no_NO"); ?>
<?php echo strftime("%A"); ?>
This will return "Fredag" (Norwegian for the day Friday)
strftime has an optional second parameter, a timestamp that specifies the date / time you want to format.
The example above have no second parameter. Then the default date / time is now.
If you format the date field in your SQL query as timestamp, then you can add your date field to the second parameter in the strftime function.
<?php setlocale(LC_TIME, "no_NO"); ?>
<?php echo strftime('%e', strtotime($row_Recordset['Yourdate'])); ?>. <?php echo strftime('%B', strtotime($row_Recordset['Yourdate'])); ?> <?php echo date("Y", strtotime($row_Recordset['Yourdate'])); ?>
This will return
4. mars 2013 (norwegian) instead of 04. March 2013 (english default)
You can also use the same approach if you want to change time from 5 to 17:00 (12 to 24 hours)
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.
Comments will be sent to the author of this tutorial and may not be answered immediately. For general help from WebAssist, please visit technical support.Sign in to add comments