简体   繁体   English

S3 Node.js SDK,LastModified日期格式?

[英]S3 Node.js SDK, LastModified date format?

I'm using the S3 SDK for Node to make a request and list bucket contents (photos). 我正在使用S3 SDK for Node来发出请求并列出存储桶内容(照片)。 I then need to sort these contents based on the LastModified date. 然后,我需要根据LastModified日期这些内容进行排序 This is the format of the date it's returning (which I'm not really sure what that format even is/why AWS is doing it like that: 这是它返回的日期的格式(我不确定那个格式甚至是什么/为什么AWS这样做:

Tue Jul 05 2016 11:00:52 GMT-0400 (EDT)

I tried using the Date.parse() method and using Moment.js to parse but to no avail. 我尝试使用Date.parse()方法并使用Moment.js解析但无济于事。

In fact, Moment says it's an invalid date: 事实上,Moment说这是一个无效的日期:

var day = moment("Tue Jul 05 2016 11:00:52 GMT-0400 (EDT)").isValid(); // false

Has anyone else experienced this before with the S3 Node SDK? 有没有其他人在使用S3 Node SDK之前遇到过这种情况? And why is the date formatted like this? 为什么日期格式如下?

When I looked at this today, I noticed the format of an object's LastModified date in S3 is not the same as what was originally posted. 当我今天看到这个时,我注意到S3中对象的LastModified日期的格式与最初发布的日期不同。 This is the response I got back from S3: (notice the day and month are flipped) 这是我从S3回来的回复:(注意日期和月份都被翻转)

LastModified: 'Mon, 06 Feb 2017 00:00:35 GMT'

So I had to update the format based on the answer from @idbehold 所以我必须根据@idbehold的答案更新格式

const lastModified = moment(result.LastModified, 'ddd, DD MMM YYYY HH:mm:ss ZZ');

这似乎正确地解析了你的日期:

moment('Tue Jul 05 2016 11:00:52 GMT-0400 (EDT)', 'ddd MMM DD YYYY HH:mm:ss ZZ')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM