Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-16-2012, 09:23 PM   PM User | #1
kiwis
New Coder

 
Join Date: Mar 2007
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
kiwis is an unknown quantity at this point
How can i publish the date being in custom format

This is my code

Code:
myDate.setMonth(myDate.getMonth()+1); 
	document.getElementById("demo").innerHTML = myDate.toDateString("m/dd/yy");
but the output is

Sat Jul 21 1990

I don't want the day of week (Sat) or the day number (21)
kiwis is offline   Reply With Quote
Old 11-16-2012, 09:48 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,468
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
You haven't provided the code that defines how the toDateString method you have added to dates is defined. From the look of that output it appears that it totally ignores the parameter you entered but without seeing the code there is no way to tell for certain.

If you are going to add a method for formatting the date the way you want rather than just joining the fields together then you ought to use one that works - see http://www.felgall.com/datemethods.htm for one alternative where myDate.format('n/d/y') will return the date in the format you want.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-16-2012, 10:19 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm...he does *NOT* want the DAY to show. And he seems to want a 4-digit year and the month name abbreviated.

So should your method be invoked with myDate.format('M Y') ???
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-16-2012, 10:59 PM   PM User | #4
kiwis
New Coder

 
Join Date: Mar 2007
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
kiwis is an unknown quantity at this point
when i do this

Code:
document.getElementById("demo").innerHTML = myDate.format('jS F, Y');
nothing displays
kiwis is offline   Reply With Quote
Old 11-16-2012, 11:17 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Did you download Felgall's code library???
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-17-2012, 12:25 AM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by felgall View Post
You haven't provided the code that defines how the toDateString method you have added to dates is defined.

lol, i'll do it for him since HE didn't add it (brendan did):

Code:
new Date().toDateString == function toDateString() { [native code] }

you don't need a whole library to replace a few simple lines of code, that's like adding jQuery to alter document.title using $("title").html("hello")...

Code:
var d=new Date(),
 s= [
   d.getMonth()+1,
   d.getDate(),
   d.getFullYear().toString().slice(2)
  ].join("/");

alert(s); // === "11/16/12"
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 11-17-2012, 12:38 AM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Except, again, he *SEEMED* to say he wants the NAME of the month and *NOT* the day of the month, at all.

So:
Code:
    var mnames = ["Jan","Feb","Mar","Apr","May","Jun",
                  "Jul","Aug","Sep","Oct","Nov","Dec" ];

    var d = new Date();
    alert( mnames[d.getMonth()] + " " + d.getFullYear() );
But who knows?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-17-2012, 01:26 AM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,468
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Old Pedant View Post
Did you download Felgall's code library???
obviously not or the date would have displayed - I use that particular combination quite a lot myself, it was one of the main reasons i started creating that library.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 11-17-2012, 01:28 AM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
(Actually, I think I knew the answer before I asked the question. I was being nice.)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:40 AM.


Advertisement
Log in to turn off these ads.