calendarxp Site Admin
Joined: 30 Jan 2005 Posts: 409
|
Posted: Tue Feb 15, 2005 6:48 pm Post subject: How to customize a date format to be like "Monday, August 18, 2003"? |
|
|
Although most common date formats can be easily set via the theme options, sometimes user do need special customized ones. It's not difficult as long as you know how to intercept the input and output of the calendar.
Now let's illustrate the process of setting a format of "WEEKDAY, MMM DD, YYYY", which is not directly supported by the theme.
1st, set the date format in the theme-name.js (e.g. normal.js) file to be "YYYY-MMM-DD", as following
Code: | var gsSplit="-"; // separator of date string, AT LEAST one char.
var giDatePos=2; // date format sequence 0: D-M-Y ; 1: M-D-Y; 2: Y-M-D
var gbPadZero=false; // whether to pad the digits with 0 in the left when less than 10.
var giMonthMode=1; // month format 0: digits ; 1: full name from gMonths; >2: abbreviated name
var gbShortYear=false; // year format true: 2-digits; false: 4-digits |
2nd, add the following to your plugins.js:
Code: | function fParseInput(str) {
var dt=/^(\w+), (\w+) (\d{1,2}), (\d{4})$/.exec(str);
if (dt==null) return null;
else return fParseDate(dt[4]+gsSplit+dt[2]+gsSplit+dt[3]);
}
function fFormatInput(y,m,d) {
var str=fFormatDate(y,m,d).split(gsSplit);
var d=new Date(y,m-1,d).getDay();
var wd=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
return wd[d]+", "+str[1]+" "+str[2]+", "+str[0];
} |
Note: We used the regular expression in the fParseInput to simplify the parsing code. You may need to change it whenever you need a different format.
_________________ Copyright 2003-2011 Idemfactor Solutions, Inc. All rights reserved. |
|