문제

I am using the YouTube API and it returns uploaded & updated times in this format: 2013-05-13T13:12:42.000Z (ISO 8601). How can I get the relative time using Javascript (or jQuery)?

Some sources that I've tried to combine to get this to work, however they all appear to format the date differently.

Javascript time to relative

Format ISO-8601 into a date object

도움이 되었습니까?

해결책

Use this timeDifference(new Date(), new Date().setTime(Date.parse("2013-05-13T13:12:42.000Z")))

If you have a problem with the "(ISO 8601)" part, use this timeDifference(new Date(), new Date().setTime(Date.parse("2013-05-13T13:12:42.000Z (ISO 8601)".replace(/ *\(.*\)/,""))))

다른 팁

Click here to check the Demo

var MyDate = new Date(
                    Date.parse
                    (
                        "2013-05-13T13:12:42.000Z (ISO 8601)"
                        .replace(/ *\(.*\)/,"")
                    )
                );

var date_Str = MyDate.getMonth()      + 
                         1            + 
                       "/"            + 
               MyDate.getDate()       + 
                       "/"            +  
               MyDate.getFullYear();

Add more function

1. MyDate.getHours()
2. MyDate.getMinutes()
3. MyDate.getSeconds()

Result - "5/13/2013"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top