【问题标题】:Current time in YouTube date API formatYouTube 日期 API 格式的当前时间
【发布时间】:2013-05-26 04:08:25
【问题描述】:

我正在使用 YouTube API,它以以下格式返回上传和更新时间:2013-05-13T13:12:42.000Z (ISO 8601)。如何使用 Javascript(或 jQuery)获取相对时间?

我尝试结合一些来源以使其正常工作,但是它们似乎都以不同的方式格式化日期。

Javascript time to relative

Format ISO-8601 into a date object

【问题讨论】:

  • 您希望如何格式化日期?
  • 以第一个链接可以读取的方式(Javascript时间到相对)。

标签: javascript jquery date youtube iso8601


【解决方案1】:

使用这个timeDifference(new Date(), new Date().setTime(Date.parse("2013-05-13T13:12:42.000Z")))

如果您对“(ISO 8601)”部分有疑问,请使用此timeDifference(new Date(), new Date().setTime(Date.parse("2013-05-13T13:12:42.000Z (ISO 8601)".replace(/ *\(.*\)/,""))))

【讨论】:

    【解决方案2】:

    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();
    

    添加更多功能

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

    结果 - “2013 年 5 月 13 日”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 2017-01-17
      • 2014-04-29
      • 2015-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多