Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    mrx
    mrx is offline
    New Coder
    Join Date
    Oct 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    date time format

    how to display day of the week and month in word not number

    day of the week: Mon or Tue etc..
    month: Nov, Dec

    thanks

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For just english? An easy way is

    Code:
    var dayName = [
      "Sunday",
      "Monday",
      "Tuesday",
    .
    .
    .
    ];
    then if you have a var dayNum (between 0-6) just

    alert(dayName[dayNum]);

    david_kw

  • #3
    Banned
    Join Date
    Oct 2005
    Location
    I'm in GMT -5
    Posts
    314
    Thanks
    0
    Thanked 1 Time in 1 Post
    mrx:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Any Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    
    	function init(){
    
    		alert(new Date().toLocaleString());
    		alert(new Date());
    
    		var shortDay = new Date().toString().split(" ")[0];
    		var longDay = new Date().toLocaleString().split(",")[0];
    		var shortMonth = new Date().toString().split(" ")[1];
    		var longMonth = new Date().toLocaleString().split(",")[1].replace(/\d+|\s+/g,"");
    	
    		document.forms[0].dayName.value = longDay;
    		document.forms[0].monthName.value = longMonth;
    
    		document.getElementById('demo').innerHTML = "Today is a " + shortDay + " in " + shortMonth;
    	}
    	
    	onload=init;
    	
    </script>
    <style type="text/css">
    
    	 body {background-color:#eae3c6;margin-top:60px}
    	 form {width:230px;margin:auto}
    	 fieldset {width:230px;background-color:#f0fff0;border:1px solid #87ceeb}
    	 legend {font-family:times;font-size:14pt;color:#00008b;background-color:#87ceeb;padding-left:3px;padding-right:3px;margin-bottom:5px}
    	 label {font-family:times;font-size:12pt;color:#00008b;padding:5px}
    	.submitBtn {font-family:tahoma;font-size:10pt;display:block;margin-left:auto;margin-right:auto;margin-top:5px;margin-bottom:5px}
    	#demo {font-family:tahoma:font-size:14pt;color:#0000cd;font-weight:bold;background-color:#ff8c00;adding:5px;text-align:center;margin:10px}	
    
    </style>
    </head>
    	<body>
    		<div id='demo'></div>
    		<form method="post" action="">
    		   <fieldset>
    			<legend>Day and Month</legend>
    				<label>Day Name:&nbsp;&nbsp&nbsp;&nbsp&nbsp;<input type='text' name='dayName' size='15' readonly></label>
    				<label>Month Name: <input type='text' name='monthName' size='15' readonly></label>
    			<input type='submit' name='submit' value="Submit" class='submitBtn'>
    		   </fieldset>
    		</form>
    	</body>
    </html>

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know if it is useful or not but Ancora inspired me to make mine more flexible. So using his date parsing code I put together this

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
      <head>
        <title>Junque</title>
        <script type="text/javascript">
          function setDiv(div, s) {
            document.getElementById(div, s).innerHTML = s;
          }
    
          function findDayName(n, bIsShort) {
            if (n < 1 || n > 7) return("Unknown");
            var dt = new Date();
            dt.setFullYear(1995, 0, n); 
            var shortDay = dt.toString().split(" ")[0];
            var longDay = dt.toLocaleString().split(",")[0];
    
            return((bIsShort) ? shortDay : longDay);
          }
    
          function findMonthName(n, bIsShort) {
            if (n < 1 || n > 12) return("Unknown");
            var dt = new Date();
            dt.setFullYear(1995, n - 1, 1); 
            var shortMonth = dt.toString().split(" ")[1];
            var longMonth = dt.toLocaleString().split(",")[1].replace(/\d+|\s+/g,"");
    
            return((bIsShort) ? shortMonth : longMonth);
          }
    
          function findNames() {
            var dayNum = parseInt(document.f.daynum.value);
            var monthNum = parseInt(document.f.monthnum.value);
            var isShort = document.f.isshort.checked;
            setDiv("adiv", "The day is " + findDayName(dayNum, isShort));
            setDiv("bdiv", "The month is " + findMonthName(monthNum, isShort));
          }
        </script>
      </head>
      <body>
        <div>
          <form name="f" action="#" onsubmit="return(false);">
            <label>Enter day number (1-7) <input type="text" name="daynum" value="1" /></label>
            <br />
            <label>Enter month number (1-12) <input type="text" name="monthnum" value="1" /></label>
            <br />
            <label>Check for short name <input type="checkbox" name="isshort" /></label>
            <button onclick="findNames();">Find Names</button>
          </form>
          <br />
          <div id="adiv"> </div>
          <div id="bdiv"> </div>
        </div>
      </body>
    </html>
    david_kw

  • #5
    mrx
    mrx is offline
    New Coder
    Join Date
    Oct 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi thanks guys
    i have my page here
    http://s91404860.onlinehome.us/tz3b.html

    how should i interate with what i have

  • #6
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It depends what you want. The date turned in to text? Seperate columns for day of the week and month? Something else?

  • #7
    mrx
    mrx is offline
    New Coder
    Join Date
    Oct 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i like to make the date to display
    in something like this format Nov 1, Tue
    instead of right now 11/1

  • #8
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A bit easier than your first question. Try changing this function

    Code:
    Event.prototype.getDay = function () {
      var arr = this.date.toString().split(" ");
      arr.length = 3;
      return arr.join(" ");
    }
    david_kw


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •