Avatar of Victor Kimura
Victor Kimura
Flag for Canada asked on

return Javascript Date object rather than string

Hi,

I have this object returned as:
events : [
            {
                "id":1,
                "start": Thu May 28 2012 14:00:00 GMT-0700 (Pacific Daylight Time),
                "end": Thu May 28 2012 15:00:00 GMT-0700 (Pacific Daylight Time),
                "title":"Lunch with Mike"
            },
            {
                "id":2,
                "start": Thu May 30 2012 16:00:00 GMT-0700 (Pacific Daylight Time),
                "end": Thu May 30 2012 18:30:00 GMT-0700 (Pacific Daylight Time),
                "title":"Dev Meeting"
            }]

But I need to return the "start" and "end" dates as:

events : [
            {
                "id":1,
                "start": new Date(year, month, day, 12),
                "end": new Date(year, month, day, 13, 30),
                "title":"Lunch with Mike"
            },
            {
                "id":2,
                "start": new Date(year, month, day, 14),
                "end": new Date(year, month, day, 14, 45),
                "title":"Dev Meeting"
            }]

How do I convert the string to the Date object? Is there an easy way? I'm drawing the "start" and "end" dates in the string format from the database.

Thanks,
Victor
JavaScriptjQueryAJAX

Avatar of undefined
Last Comment
HonorGod

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
HonorGod

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Victor Kimura

ASKER
Thank you. That works. =)
HonorGod

You are welcome.  Thanks for the grade & points.

Good luck & have a great day.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes