Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQUERY DATE FORMAT

Posted on 2013-01-19
6
Medium Priority
?
2,011 Views
Last Modified: 2013-03-09
Hi,
I am new to jquery and need to use a date formatted in the  UK style I am using  var date1 = new Date(); to obtain the date and have attempted to convert the date returned 'Sat Jan 19 2013 16:52:39 GMT+0100 (W. Europe Standard Time)'  to the format 'dd/mm/yy hh:mm' how to I achive this?
0
Comment
Question by:JoeBo747
[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
6 Comments
 
LVL 43

Accepted Solution

by:
David S. earned 750 total points
ID: 38797688
0
 
LVL 53

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 750 total points
ID: 38797719
You can just ust the toString() function I think and it will go to the local time zone
<script>
var date1 = new Date(); 
var date2=date1.toString();
$('div.time').text(date2);
</script>
 <div class="time"></div>

Open in new window

and for reference some help below
http://docs.jquery.com/UI/Datepicker/formatDate
http://www.w3schools.com/jsref/jsref_obj_date.asp
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38797757
Here is the top link in google for this FAQ
http://stackoverflow.com/questions/1056728/formatting-a-date-in-javascript

it mentions moment.js which is the library to use if you don't already use jQuery UI
http://momentjs.com/
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 38798828
<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        
    </head>
    <body>
        <div id="date"></div>
        <script>
            
           ( function writeDate(){
            var date    = new Date(),
                month   = date.getMonth() + 1, // 0-11,
                day     = date.getDate(), 
                year    = date.getFullYear(),
                hour    = date.getHours(),
                minute  = date.getMinutes();
            
                year = year.toString().slice(2,4);
            
            
                var dateContainer = document.getElementById("date");
                dateContainer.innerHTML = day+"/"+month+"/"+year+" "+hour+":"+minute;
            })();
            </script>
    </body>
</html>

Open in new window

Do you want to include leading 0's?

In this example the script is at the bottom of the page so you don't need an onload event. If you want to put this script at the top of your page, you'll need a window.onload event.
0
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 38798846
here's a version with leading 0's

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta charset="UTF-8">
        
    </head>
    <body>
        <div id="date"></div>
        <script>
            
           ( function writeDate(){
            var date    = new Date(),
                month   = date.getMonth() + 1, // 0-11,
                day     = date.getDate(),
                year    = date.getFullYear(),
                hour    = date.getHours(),
                minute  = date.getMinutes();
            
                year = year.toString().slice(2,4);
                
                
                month = month < 10 ? "0"+month : month;
                minute = minute < 10 ? "0"+minute : minute;
            
                var dateContainer = document.getElementById("date");
                dateContainer.innerHTML = day+"/"+month+"/"+year+" "+hour+":"+minute;
            })();
            </script>
    </body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:JoeBo747
ID: 38798950
Sorry I have not abandoned this post I have been travelling and will catch up tomorrow.
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

662 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