显示英文日期

[ 2006-12-06 14:55:43 | 作者: admin ]
字号: | |
Javascript 函数
Showdate ( [date object|string], [day string], [month string], [date string], [year string], [delimeter string] )

Date:- Javascript date object in the form new Date(), new Date(1982,06,30).
Day:- Day string in the form "dddd" or "ddd".
Month:- Month string in the form "mmmm", "mmm", "mm".
Date:- Date string in the form "dddd", "ddd", "dd", "d".
Year:- Year string in the form "yyyy", "yy".
 
例子 效果
Showdate(new Date(), 'dddd', 'mmm', 'dd', 'yyyy', '-')
Wednesday, December-06-2006
Showdate(new Date(), 'dd', 'mm', 'dd', 'yyyy', '.')
0612.06.2006
Showdate(new Date(2001,11,25), 'dddd', 'mmm', 'dd', 'yy', ' ')
Tuesday, Dec 25 01

函数部分
<script language=javascript>

var aDay = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var aMonth = new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function DateFormat(xdate,x)
{
/*
Date Format function to be used in internally by the Showdate function.
Returns either: d, dd, ddd, dddd, m, mm, mmm, mmmm, y, yy, yyy, yyyy.
eg. Sun Sep 28 09:22:08 EDT 2003 returns 28, 28, Sun., Sunday, 9, 09, Sep., September, 03, 03, 03, 2003
Sun Sep 28 09:22:08 EDT 2003 = 28 28 Sun. Sunday, 9 09 Sep. September, 03 03 03 2003
*/
x = x.toLowerCase();
return (((x == "d") ? xdate.getDate() : ((x == "dd") ? ((xdate.getDate() <= 9) ? "0"+xdate.getDate() : xdate.getDate()) : ((x == "ddd") ? aDay[xdate.getDay()].substring(0,3)+". " : ((x == "dddd") ? aDay[xdate.getDay()]+", " : ((x == "m") ? xdate.getMonth()+1 : ((x == "mm") ? (((xdate.getMonth()+1) <= 9) ? "0"+(xdate.getMonth()+1) : xdate.getMonth()+1) : ((x == "mmm") ? aMonth[xdate.getMonth()].substring(0,3) : ((x == "mmmm") ? aMonth[xdate.getMonth()] : ((x == "y" || x == "yy" || x == "yyy") ? xdate.getFullYear().toString().substring(2,4) : ((x == "yyyy") ? xdate.getFullYear().toString() : "")))))))))))
}

function Showdate(_date, _var1, _var2, _var3, _var4, _del)
{
// ----------------------------------------------------------------------------------------
// Content: Date formatter where _month = month, _day = day of week spelled out, yyyy = four digit year.
// The script will only display a day spelled out if the parameter is ddd, or dddd. dd or d means do not display the day.
//
// Syntax: document.writeln(Showdate(date object, "ddd", "mmm", "dd", "yyyy", "-"));
// where date can be a field variable = rs("Datecreated"); constant= new Date(yyyy,m,dd);
//
// Results in: Thursday, January-01-1970 NOTE that the numeric month in Javascript is from 0-11
//
// timerID=setInterval("if (_ie){++nd; if (nd > xStyle.length) nd=0; document.all.md.innerHTML=Showdate(null, "mmm", "ddd", "yy" , "-");}",3000)
// timerOn=true
// ----------------------------------------------------------------------------------------

var today = (_date == null) ? new Date() : new Date(_date);
_del = ((_del == null) ? " " : _del);
return ( DateFormat(today, _var1) + DateFormat(today, _var2) + ((_var2 != "")? _del : "") + DateFormat(today, _var3) + ((_var3 != "")? _del : "") + DateFormat(today, _var4))
}

</script>
[最后修改由 admin, 于 2006-12-06 15:00:44]
评论Feed 评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=765

这篇日志没有评论。

此日志不可发表评论。