datejs

Parse 'Date & Time' string in Javascript which are of custom format

自作多情 提交于 2019-12-18 03:17:28
问题 I have to parse a date and time string of format "2015-01-16 22:15:00". I want to parse this into JavaScript Date Object. Any help on this? I tried some jquery plugins, moment.js, date.js, xdate.js. Still no luck. 回答1: With moment.js you can create a moment object using the String+Format constructor: var momentDate = moment('2015-01-16 22:15:00', 'YYYY-MM-DD HH:mm:ss'); Then, you can convert it to JavaScript Date Object using toDate() method: var jsDate = momentDate.toDate(); 回答2: A better

Work with a time span in Javascript

て烟熏妆下的殇ゞ 提交于 2019-12-17 10:44:59
问题 Using Date.js already, but can also use another library if necessary. Not sure what is the best way to work with time deltas. Specifically, I want to display the time that has elapsed between now and a past date-time. So I need to do something like this: var elapsed_time = new Date() - pastDate; pastDate.toString('days-hours-minutes-seconds'); Gotten it to mostly work using Date.js, but the problem is now I'm working with a Date object and not a timespan, so what should be an 23 hour time

Javascript using datejs to parse RFC3339 datetime

回眸只為那壹抹淺笑 提交于 2019-12-14 01:08:35
问题 I'm having trouble using datajs with a date format from Google Calendar API. The datetime format I believe is RFC3339 and this is a sample datetime returned from the calendar api 2012-01-05T08:45:00Z This is from the datejs documentation here Date.parse('1985-04-12T23:20:50Z') // RFC 3339 Formats But this just returns null. I'm assuming I have datejs working correctly as Date.today().next().friday() returns Fri May 11 2012 00:00:00 GMT+0100 (BST) 回答1: SOLVED : Use Date.parseExact OR this

DateJS - Do Not Include Weeknds

社会主义新天地 提交于 2019-12-13 07:46:34
问题 I have DateJS set up on my website to give users the ability to know when they will receive their package. I am utilizing DateJS script to do this. I need to modify the script so that it does not include weekends when estimating the delivery day. For example, today (Friday), if someone selects one of the following: Next Day Air: it should show Monday, not Saturday Two Day Air: It should show Tuesday, not Sunday Three Day Air: It should show Wednesday, not Monday Help is greatly appreciated.

Convert JavaScript DateTime to UTC with no milliseconds

不羁岁月 提交于 2019-12-12 22:09:07
问题 Right now I'm trying to parse a date that's written in a human-readable format into a DateTime String that a SharePoint list will accept. In order to do this I've determined that I need a String in a format similar to ISO that looks like: 2007-08-20T00:00:00Z . It seems that SharePoint only accepts DateTimes that are in UTC with no milliseconds included (for whatever reason, SharePoint gives errors and won't accept the DateTime when you include the milliseconds), so I need to convert my local

date.js Parse method overrides Javascript Parse method

最后都变了- 提交于 2019-12-12 18:37:58
问题 I'm including the date.js library in my site because I need its functionality. I have just realized, though, that the standard Javascript parse() method is overwritten by it. I'm trying to build a line chart in Highcharts, and the data series wants the first element to be be in milliseconds (their demos show them using the Date.UTC() method to achieve this, but my data is returned in a different format). Short of doing a bunch of string manipulation to put my data into a format that Date.UTC

Date.js parseExact() not parsing 4 digit years when passed in as an array

只谈情不闲聊 提交于 2019-12-12 12:17:40
问题 Am I missing something with Date.parseExact() in date.js? According to the api documentation, I should be able to do this: Date.parseExact("10/15/2004", ["M/d/yyyy", "MMMM d, yyyy"]); // The Date of 15-Oct-2004 That is, I should be able to pass in a string array which contains "...the expected format {String} or an array of expected formats {Array} of the date string." However, when I do this: var d = Date.parseExact($(this).val(), ["MMddyy", "Mddyyyy", "MM/dd/yy","MM/dd/yyyy"]) I get back

Using Datejs - Get the day of the week

痞子三分冷 提交于 2019-12-11 02:49:20
问题 I'm using http://www.datejs.com/. I must be missing it, but is there a way I can pass it the day/month/year and have it tell me that it's a Friday or Monday or whatever? 回答1: You want: .toString("dddd"); For example: > Date.parse("1.16.2012").toString("dddd"); "Monday" 回答2: If you want to know whether it is a particular day of the week, you could do this: Date.parse("1.16.2012").is().monday() 来源: https://stackoverflow.com/questions/8889339/using-datejs-get-the-day-of-the-week

DateJS parsing mystery

大憨熊 提交于 2019-12-10 03:49:12
问题 I'm using DateJS to parse user-inputted dates, and getting some strange results. Date.parse("15 Jan 2010") returns Fri Jan 15 00:00:00 EST 2010 (right) Date.parse("15-Apr-2010") returns Thu Apr 15 00:00:00 EDT 2010 (right) Date.parse("15 Apr 2010") returns Thu Apr 1 00:00:00 EDT 2010 (wrong) As far as I can tell, the d MMM yyyy input format works fine for every month except April and August; in those two cases, it returns the first of the month no matter what day is entered. Is this a bug, or

在哪里可以找到有关在JavaScript中格式化日期的文档? [关闭]

非 Y 不嫁゛ 提交于 2019-12-09 12:15:43
我注意到JavaScript的 new Date() 函数非常聪明,可以接受多种格式的日期。 Xmas95 = new Date("25 Dec, 1995 23:15:00") Xmas95 = new Date("2009 06 12,12:52:39") Xmas95 = new Date("20 09 2006,12:52:39") 在调用 new Date() 函数时,找不到任何显示所有有效字符串格式的文档。 这是用于将字符串转换为日期。 如果我们从相反的角度来看,也就是将日期对象转换为字符串,直到现在,我仍然觉得JavaScript没有内置的API将日期对象格式化为字符串。 编者按: 以下方法是提问者的企图是工作在一个特定的浏览器,但一般 不 工作; 请参阅本页上的答案 以查看一些实际解决方案。 今天,我在date对象上使用 toString() 方法,令人惊讶的是,它用于将日期格式化为字符串的目的。 var d1 = new Date(); d1.toString('yyyy-MM-dd'); //Returns "2009-06-29" in Internet Explorer, but not Firefox or Chrome d1.toString('dddd, MMMM ,yyyy') //Returns "Monday, June 29,2009" in