troubleshooting Question

return Javascript Date object rather than string

Avatar of Victor Kimura
Victor KimuraFlag for Canada asked on
JavaScriptAJAXjQuery
3 Comments1 Solution321 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
HonorGod
Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros