function FormatDateTime(datetime, FormatType)
/*
FomatType takes the following values
1 - General Date = Friday, October 30, 1998
2 - Typical Date = 10/30/98
3 - Standard Time = 6:31 PM
4 - Military Time = 18:31
*/
{
var strDate = new String(datetime);
if (strDate.toUpperCase() == "NOW") {
var myDate = new Date();
strDate = String(myDate);
} else {
var myDate = new Date(datetime);
strDate = String(myDate);
}
// Get the date variable parts
var Day = new String(strDate.substring(0,3));
if (Day == "Sun") Day = "Sunday";
if (Day == "Mon") Day = "Monday";
if (Day == "Tue") Day = "Tuesday";
if (Day == "Wed") Day = "Wednesday";
if (Day == "Thu") Day = "Thursday";
if (Day == "Fri") Day = "Friday";
if (Day == "Sat") Day = "Saturday";
var Month = new String(strDate.substring(4,7)), MonthNumber = 0;
if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
if (Month == "Feb") { Month = "February"; MonthNumber = 2; }
if (Month == "Mar") { Month = "March"; MonthNumber = 3; }
if (Month == "Apr") { Month = "April"; MonthNumber = 4; }
if (Month == "May") { Month = "May"; MonthNumber = 5; }
if (Month == "Jun") { Month = "June"; MonthNumber = 6; }
if (Month == "Jul") { Month = "July"; MonthNumber = 7; }
if (Month == "Aug") { Month = "August"; MonthNumber = 8; }
if (Month == "Sep") { Month = "September"; MonthNumber = 9; }
if (Month == "Oct") { Month = "October"; MonthNumber = 10; }
if (Month == "Nov") { Month = "November"; MonthNumber = 11; }
if (Month == "Dec") { Month = "December"; MonthNumber = 12; }
var curPos = 11;
var MonthDay = new String(strDate.substring(8,10));
if (MonthDay.charAt(1) == " ") {
MonthDay = "0" + MonthDay.charAt(0);
curPos--;
}
var MilitaryTime = new String(strDate.substring(curPos,curPos + 5));
var Year = new String(strDate.substring(strDate.length - 4, strDate.length));
document.write(strDate + "");
// Format Type decision time!
if (FormatType == 1)
strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
else if (FormatType == 2)
strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
else if (FormatType == 3) {
var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
if (MilitaryTime.substring(0,2) > 12)
strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
else {
if (MilitaryTime.substring(0,2) < 10)
strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
else
strDate = MilitaryTime + AMPM;
}
}
else if (FormatType == 4)
strDate = MilitaryTime;
return strDate;
}
| file: /techref/language/asp/js/formatDateTime.htm, 2KB, , updated: 2008/2/2 12:33, local time: 2008/11/22 05:12,
38.103.63.58:LOG IN
|
| ©2008 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/language/asp/js/formatDateTime.htm"> language asp js formatDateTime</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20081122 Apptech, Jinx, Xiaofan Chen, olin piclist, Vitaliy, William \Chops\ Westfield, Tamas Rudnai, JonnyMac, Alan B. Pearce, Gerhard Fiedler, * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Shultz Electronics, Timothy Weber, on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
|
.