?
Solved

using Date function in jQuery

Posted on 2016-09-29
3
Medium Priority
?
54 Views
Last Modified: 2016-10-01
I'm using jQuery

If i use this function

var d = new Date();

That saves today's date in the variable called d in this format:   Thu Sep 29 2016 21:59:45 GMT-0800 (Pacific Standard Time)

How do I revise the Format so it saves today's date in this format?:    09/29/2016
0
Comment
Question by:maqskywalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 1000 total points
ID: 41822946
try:
<script>
      var d = new Date();
      document.write("<br>Before: " + d);
      var d2 = ((d.getMonth() < 9) ? ("0" + (d.getMonth() + 1)) : d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear();
      document.write("<br>After: " + d2);
  </script>

Open in new window

0
 
LVL 35

Assisted Solution

by:ste5an
ste5an earned 1000 total points
ID: 41823186
That saves today's date in the variable called d in this format[..]

Nope, that's wrong. It is saved in a internal numeric format. But there is no other way to display it, by using a format. The default format is specified by using the browsers locale:

var dt = new Date('2013-01-30');
console.log(dt.toUTCString());
console.log(dt.toString());

Open in new window


Imho the best way to deal with it, is to use moment.js:

console.log(moment().format('MM/DD/YYYY'));
// or
moment.locale('en');
console.log(moment().format('L'));

Open in new window

0
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 41825045
Thanks
0

Featured Post

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question