jquery将日期转换为格式化日期

时间:2018-05-22 23:14:24

标签: javascript jquery

我正在使用jquery / javascript并尝试将日期格式转换为日期+小时分钟。 我试过新的日期(myFormatDate),但它给了我完整的日期,包括时区。新Date()的子字符串只是获取格式的选项吗?

From Format I am trying to convert 
"2018-05-17T00:55:46"

To Format I am trying to achieve
2018-05-01 23:17:32.00

3 个答案:

答案 0 :(得分:1)

如果想要这个具体案例,我认为这是最好的方式:

var someDate = new Date("2018-05-17T00:55:46");
var formatted = someDate.toISOString().slice(0,10) + " " + someDate.toISOString().slice(11,22);

答案 1 :(得分:1)

我希望这个功能可以帮到你

SELECT Owner.id, Owner.address, 
       Borrowable.author, Borrowable.title, Borrowable.isbn, 
       Borrowable.collection_name, Borrowable.collection_id, Borrowable.volume_number, 
       Borrowable.can_be_borrowed
FROM Owner
LEFT JOIN (SELECT owner_id, 
                  author, title, isbn, 
                  collection_name, collection_id, volume_number, can_be_borrowed,
                  ROW_NUMBER() OVER(PARTITION BY owner_id, collection_name 
                                    -- Include book_id to make the sort stable
                                    ORDER BY can_be_borrowed DESC NULLS LAST, book_id) as first_borrowable
           FROM Book) AS Borrowable
       ON Borrowable.owner_id = Owner.id
          AND Borrowable.first_borrowable = 1
-- So that all collections belonging to the same owner are together
ORDER BY Owner.owner_id, Borrowable.isbn, Borrowable.collection_name, Borrowable.volume_number, Borrowable.can_be_borrowed

答案 2 :(得分:1)

使用其他库,例如moment.js(https://momentjs.com/

以下是几个例子

moment().format('MMMM Do YYYY, h:mm:ss a'); // May 23rd 2018, 8:41:58 am
moment().format('dddd');                    // Wednesday
moment().format("MMM Do YY");               // May 23rd 18