1

So what I want to do is get new Date():

Wed Oct 02 2013 22:15:00 GMT-0400 (EDT)

And replace the 22:15:00 for something else...

Is that possible using jquery?

2 Answers 2

4

You can use a regex and .replace()

'Wed Oct 02 2013 22:15:00 GMT-0400 (EDT)'.replace(/\d\d:\d\d:\d\d/, '00:00:00')
Sign up to request clarification or add additional context in comments.

3 Comments

I get a "Uncaught TypeError: Object [object Date] has no method 'replace'" any idea why?
I'm doing this var l = new Date; then l.replace(/\d\d:\d\d:\d\d/, '00:00:00')
@Darkagelink in that case see the next answer by stevaity ... use l.setHours(0); l.setMinutes(0); l.setSeconds(0);
2

I think you need a generic solution. You could go for a regex based solution. But lets keep it simple.

What you have in hand is a Date object right? The Date object supports methods like setHours(), setMinutes() and setSeconds(). Use them to change the time!

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

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.