首页 > 解决方案 > 我想使用 Javascript 将字符串日期“星期六,2021 年 7 月 3 日 06:06:06 GMT”转换为格式为“yyyy-MM-dd'T'HH:mm”的字符串

问题描述

任何人都可以帮助提供代码吗?

function getDateTimeinUTC(inputstringdate) {

//Code to convert "Sat, 03 Jul 2021 06:06:06 GMT to a date and then use below sort of code to convert it to yyyy-MM-dd'T'HH:mm

    var DateTimeFormatter = Java.type('java.time.format.DateTimeFormatter');
    var dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm");
    var ldt = java.time.LocalDateTime.now(java.time.ZoneOffset.UTC);
    return ldt.format(dtf);
}

标签: javascript

解决方案


简单代码:

x=new Date("Sat, 03 Jul 2021 06:06:06 GMT")

x.toISOString()

例如,在 FF 开发控制台上: 在此处输入图像描述


推荐阅读