Howto
// +----------------------------------------------------------------------+ // | SPIP.DateLocales.JS v.1.0.0-English | // +----------------------------------------------------------------------+ // | Copyright (c) 2004 Adeixis.Communication | // +----------------------------------------------------------------------+ // | This program is free software; you can redistribute it and/or | // | modify it under the terms of the GNU General Public License | // | as published by the Free Software Foundation; either version 2 | // | of the License, or (at your option) any later version. | // | | // | This program is distributed in the hope that it will be useful, | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // | To read the license, please visit: | // | http://www.gnu.org/copyleft/gpl.html | // +----------------------------------------------------------------------+ // | Author: Julien Tessier <julien@adeixis.com> | // +----------------------------------------------------------------------+ function s_lt(timestamp, format) { if (format == undefined) format = "Y-m-d H:i:s" date_object = new Date(); date_object.setTime(timestamp*1000); document.write(spipLocalTime_formatDate(date_object, format)); } function spipLocalTime_addZero(number){ return ((number < 10) ? "0" : "") + number } function spipLocalTime_formatDate(date_object, format){ var daysTextual = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sunday"); var monthsTextual = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var replacements = new Array(); replacements['d'] = spipLocalTime_addZero(date_object.getDate()); replacements['F'] = monthsTextual[date_object.getMonth()]; replacements['G'] = date_object.getHours(); replacements['H'] = spipLocalTime_addZero(date_object.getHours()); replacements['i'] = spipLocalTime_addZero(date_object.getMinutes()); replacements['j'] = date_object.getDate(); replacements['l'] = daysTextual[date_object.getDay()]; replacements['m'] = spipLocalTime_addZero(date_object.getMonth()+1); replacements['n'] = date_object.getMonth()+1; replacements['s'] = spipLocalTime_addZero(date_object.getSeconds()); replacements['Y'] = date_object.getFullYear(); replacements['y'] = spipLocalTime_addZero(date_object.getFullYear().toString().substring(3,4)); var parsed_string = ''; for (i=0; i
Download the above script, rename it as spip_localtime_en.js, upload it to the root directory of your server and write the following code in the HEAD section of your templates:
<script language="JavaScript" type="text/javascript" src="spip_localtime_en.js"></script>
Then, paste this code in yoyr mes_fonctions.php3 file:
function localtime_js($date, $format = "Y-m-d H:i:s") {
return "<script language=\"JavaScript\" type=\"text/javascript\">s_lt(".strtotime($date).", '".str_replace('\\', '\\\\', $format)."');</script><noscript>".date($format, strtotime($date))." UTC</noscript>";
}
Eventually, place this code in your templates:
[(#DATE|localtime_js{'y-m-d H:i'})]
This date format between brackets is quite the same as function date in PHP. The supported codes are: d, F, G, H, i, j, l, m, n, s, Y and y. It also supports anti-slashes to escape characters.
Limits
Server timezone needs to be UTC (or the script needs some modifications).
If the browser doesn’t support JavaScript, date and time are displayed in UTC.
Discussions by date of activity
One discussion
Hi. My server has NY’s time. I’m in Mexico (a two hours difference).
What kind of modifications should I do by using your js script?
I’m not to php savvy.
Thanks! This is my site: www.elagoradechihuahua.com
Reply to this message
Add a comment
Avant de faire part d’un problème sur un plugin X, merci de lire ce qui suit :
Merci d’avance pour les personnes qui vous aideront !
Par ailleurs, n’oubliez pas que les contributeurs et contributrices ont une vie en dehors de SPIP.
Follow the comments:
|
