Avatar of Victor Kimura
Victor KimuraFlag 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
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Victor Kimura

ASKER

Thank you. That works. =)
Avatar of HonorGod
HonorGod
Flag of United States of America image

You are welcome.  Thanks for the grade & points.

Good luck & have a great day.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo