Open GoogleCodeExporter opened 9 years ago
Currently, the default format of date is only 'mm/dd/yyyy'. In case of others,
you
should customize function such as:
JSGantt.formatDateStr = function(pDate,pFormatStr) {
vYear4Str = pDate.getFullYear() + '';
vYear2Str = vYear4Str.substring(2,4);
vMonthStr = (pDate.getMonth()+1) + '';
vDayStr = pDate.getDate() + '';
var vDateStr = "";
switch(pFormatStr) {
case 'mm/dd/yyyy':
return( vMonthStr + '/' + vDayStr + '/' + vYear4Str );
case 'mm.dd.yyyy':
return( vMonthStr + '.' + vDayStr + '.' + vYear4Str );
case 'dd.mm.yyyy':
return( vDayStr + '.' + vMonthStr + '.' + vYear4Str );
case 'dd/mm/yyyy':
return( vDayStr + '/' + vMonthStr + '/' + vYear4Str );
case 'yyyy-mm-dd':
return( vYear4Str + '-' + vMonthStr + '-' + vDayStr );
case 'yyyy.mm.dd':
return( vYear4Str + '.' + vMonthStr + '.' + vDayStr );
case 'mm/dd/yy':
return( vMonthStr + '/' + vDayStr + '/' + vYear2Str );
case 'mm.dd.yy':
return( vMonthStr + '.' + vDayStr + '.' + vYear2Str );
case 'dd/mm/yy':
return( vDayStr + '/' + vMonthStr + '/' + vYear2Str );
case 'dd.mm.yy':
return( vDayStr + '.' + vMonthStr + '.' + vYear2Str );
case 'yy-mm-dd':
return( vYear2Str + '-' + vMonthStr + '-' + vDayStr );
case 'yy.mm.dd':
return( vYear2Str + '.' + vMonthStr + '.' + vDayStr );
case 'mm/dd':
return( vMonthStr + '/' + vDayStr );
case 'dd/mm':
return( vDayStr + '/' + vMonthStr );
case 'dd.mm':
return( vDayStr + '.' + vMonthStr );
case 'mm.dd':
return( vMonthStr + '.' + vDayStr );
case 'dd-mm':
return( vDayStr + '-' + vMonthStr );
case 'mm-dd':
return( vMonthStr + '-' + vDayStr );
case 'dd-mm-yy':
return( vDayStr + '-' + vMonthStr + '-' + vYear2Str );
case 'dd-mm-yyyy':
return( vDayStr + '-' + vMonthStr + '-' + vYear4Str );
}
}
And:
JSGantt.parseDateStr = function(pDateStr,pFormatStr) {
var vDate =new Date();
vDate.setTime( Date.parse(pDateStr));
switch(pFormatStr)
{
case 'mm/dd/yyyy':
var vDateParts = pDateStr.split('/');
vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[0], 10) -
1, parseInt(vDateParts[1], 10));
break;
case 'mm.dd.yyyy':
var vDateParts = pDateStr.split('.');
vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[0], 10) -
1, parseInt(vDateParts[1], 10));
break;
case 'dd/mm/yyyy':
var vDateParts = pDateStr.split('/');
vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[0], 10));
break;
case 'yyyy-mm-dd':
var vDateParts = pDateStr.split('-');
vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[1], 10));
break;
case 'yyyy.mm.dd':
var vDateParts = pDateStr.split('.');
vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[1], 10));
break;
case 'yyyy/mm/dd':
var vDateParts = pDateStr.split('/');
vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[1], 10));
break;
case 'dd.mm.yyyy':
var vDateParts = pDateStr.split('.');
vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[0], 10));
break;
}
return(vDate);
}
Hope this help,
TN
Original comment by dat...@gmail.com
on 9 Nov 2009 at 7:16
Original issue reported on code.google.com by
weblo...@computech-it.co.uk
on 2 Oct 2009 at 12:46