1

How can i convert date which looks like this 12092008 to unixtime like this 1221215809

3 Answers 3

4

You may want to use the following:

function covertToUnixTime(yourDate) {
    return new Date(yourDate.substring(4, 8) + '/' + 
                    yourDate.substring(2, 4) + '/' + 
                    yourDate.substring(0, 2)).getTime() / 1000;
}

covertToUnixTime('12092008');   // Returns: 1221170400
Sign up to request clarification or add additional context in comments.

Comments

1

You could use jQuery datepicker's utility functions, parseDate and formatDate.

Comments

0

This worked for me.

var day = $("#day").val();
var month   = $("#month").val();
var year    = $("#year").val();
var date    = new Date();
date.setFullYear(year, month, day)
var unixtimeMS = date.getTime();
var unixtime = parseInt(unixtimeMS / 1000);
alert(unixtime);

1 Comment

You need to be very careful with this - remember that the clocks on your clients' computers may not be set to the same time zone as your servers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.