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 5 of 5
  1. #1
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts

    how to convert date to unixtine in JS

    hi ,

    i have date in (21 May 2008) this format.

    What is the function in JS to convert to unix time
    In php it was
    Code:
    strtotime("21 May 2008")
    what is the function in JS
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    725
    Thanks
    35
    Thanked 132 Times in 123 Posts
    var D=new Date(Date.parse("21 May 2008"))
    // returns Date object

    var T=Date.parse("21 May 2008")
    // returns javascript timestamp in milliseconds (not seconds)

    alert(T+'\n'+ D.toLocaleDateString())

  • #3
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    It is not showing the correct time , iwant may 21 2008 00.00 time
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #4
    Senior Coder o0O0o.o0O0o's Avatar
    Join Date
    Jan 2008
    Location
    C:\Windows\System32
    Posts
    1,018
    Thanks
    19
    Thanked 9 Times in 9 Posts
    It shows 1211353200 which is 5/21/2008 4:30:00 PM

    Which time zone does JS follows
    Last edited by o0O0o.o0O0o; 05-21-2008 at 06:09 AM.
    Please de-reputate me
    0o0o0o0

    Its better to rule in Hell then to serve in Heaven

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    You cannot extract a time when only a date DD/MM/YYYY is provided.

    If you want the current time HH:MM;SS then:

    Code:
    <script type="text/javascript">
    
    var d = new Date();
    var yy = d.getYear();
    var mm = d.getMonth()+1;
    var dd = d.getDate();
    var hh = d.getHours();
    var mn = d.getMinutes();
    var ss = d.getSeconds();
    var fd = dd+ "/"+ mm +"/" + yy + "  " + hh + ":" + mn + ":" + ss
    alert (fd);
    
    </script>
    If you have the time, then:

    var d=new Date(Date.parse("21 May 2008 10:03:20"));

    Javascript takes its time from the user's computer, that is local time. You can use UTC time (= GMT) if you wish, with an offset if desired.


    Q. If you were to spell out numbers, how far would you have to go until you would find the letter "A"?
    A. One thousand


  •  

    Posting Permissions

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