1

How can i convert this datetime format:

2013-05-04 17:25:00

To a timezone that i can specify. Something like this:

convertTimeZone('2013-05-04 17:25:00', '+3');

And return the following datetime with the specified timezone?

1

2 Answers 2

2

Hopefully this is enough to get you started

// time should be a string in your format
// offset should be an int (i.e. 3 or -3)
function convertTimeZone(time, offset) {
    time = time.replace('-','/');
    return new Date(time).addHours(parseInt(offset, 10));
}

To be called as such

convertTimeZone('2013-05-04 17:25:00', 3);
convertTimeZone('2013-05-04 17:25:00', -3);

Javascript doesn't like - so replace them with / which it will accept. None of this uses jquery, this is just basic javascript.

Sign up to request clarification or add additional context in comments.

Comments

0

Take a look at Moments.js

then you could do something like this (just an example may not match exactly what you are asking)

var date1 = moment.utc("2013-05-04 17:25:00").format("YYYY-MM-DDTHH:mm:ss");

console.log(date1.toString());

var date2 = moment.utc(date1).add("hours", 3).format("YYYY-MM-DDTHH:mm:ss");

console.log(date2.toString());

which will output

2013-05-04T17:25:00
2013-05-04T20:25:00 

On jsfiddle

Comments

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.