datejs

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

不羁的心 提交于 2019-12-08 18:01:25
我注意到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

Datejs - Problem with 12:00 pm

喜欢而已 提交于 2019-12-05 06:03:56
I really have no idea what I'm doing wrong here. I can't get Datejs to properly parse "12:00 pm" however, it seems to work fine on other dates. Below is a clip from the Firefox debugger: Download the latest version of Datejs from SVN not the version in the "download" section. Try wrapping the code in an IIFE. <!DOCTYPE html> <html> <body> <input type=text id=d onkeyup="parsedate()"> </input> <br> <span id=output></span> <script type="text/javascript" src="../../../static/js/date.js"></script> <script> ( function() { parsedate = function() { var input = document.getElementById('d').value; var

DateJS parsing mystery

ⅰ亾dé卋堺 提交于 2019-12-05 05:19:53
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 is there a logical explanation I'm missing? Aha: Looks like the version in the "Download" link is a

Get utc offset from timezone in Javascript

纵然是瞬间 提交于 2019-12-04 00:43:57
问题 I need a Javascript function that given a timezone, returns the current utc offset. For example, theFuncIneed('US/Eastern') -> 240 Any idea? Thanks 回答1: In general , this is not possible. US/Eastern is an identifier for a time zone . (It's actually an alias to America/New_York , which is the real identifier.) 240 is a time zone offset . It's more commonly written as -04:00 (Invert the sign, divide by 60). The US Eastern Time Zone is comprised of both Eastern Standard Time, which has the

Get GMT String from current Date

你离开我真会死。 提交于 2019-12-02 01:58:28
I am able to get the output format that I need, but not the correct time. I need it in GMT (which is +4 hours) var dt = new Date(); var dt2 = dt.toString('yyyyMMddhhmmss'); Any ideas? The output looks like: 20120403031408 I am able to get the GMT in standard string format by doing: dt.toUTCString(); but im unable to convert it back to the yyyyMMddhhmmss string EDIT: I am using the date.js library Jonathan Lonowski date.js 's toString(format) doesn't have an option to specify "UTC" when formatting dates. The method itself (at the bottom of the file) never references any of Date 's getUTC...

Jquery DateJs, is there validation for full date?

亡梦爱人 提交于 2019-12-01 10:24:51
问题 I just find out about the power of date js, And its great!!! As I am a newbie I was wondering if there is any kind of general validitation for different types of full dates. eg. var d1 = Date.parse('2000-10-18, 10:06 AM'); alert(d1.toString('HH:mm')); If date is ('200-10-18, 10:06 AM'), of course it doesn't like it. So my question is if there is any quick way to validate the full date, rather than having to validate one by one. Thanks. 回答1: Here I am answering your question again. To validate

Get utc offset from timezone in Javascript

落爺英雄遲暮 提交于 2019-12-01 03:20:23
I need a Javascript function that given a timezone, returns the current utc offset. For example, theFuncIneed('US/Eastern') -> 240 Any idea? Thanks Matt Johnson-Pint In general , this is not possible. US/Eastern is an identifier for a time zone . (It's actually an alias to America/New_York , which is the real identifier.) 240 is a time zone offset . It's more commonly written as -04:00 (Invert the sign, divide by 60). The US Eastern Time Zone is comprised of both Eastern Standard Time, which has the offset of -05:00 and Eastern Daylight Time, which has the offset of -04:00 . So it is not at

Parse ONLY a time string with DateJS

我们两清 提交于 2019-11-30 14:58:23
问题 I'm using the excellent (but large) DateJS library to handle dates and times in my webapp. I just came across something that I'm not sure how to handle. I want my users to be able to enter Time strings only, without a date, but they should be able to enter it in any manner they please. For instance: 5:00 pm 17:00 5:00pm 5:00p 5p etc. Using Date.parse(value) converts these strings into a full date, which is exactly what I want. However, it also allows the user to enter any other part of a date

Parse ONLY a time string with DateJS

牧云@^-^@ 提交于 2019-11-30 13:06:31
I'm using the excellent (but large) DateJS library to handle dates and times in my webapp. I just came across something that I'm not sure how to handle. I want my users to be able to enter Time strings only, without a date, but they should be able to enter it in any manner they please. For instance: 5:00 pm 17:00 5:00pm 5:00p 5p etc. Using Date.parse(value) converts these strings into a full date, which is exactly what I want. However, it also allows the user to enter any other part of a date string, such as: sat 5pm 1/1/2010 5pm etc. I'm trying to use DateJS to validate an input field for a

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

孤人 提交于 2019-11-29 01:35:53
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. 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(); new Date("2015-01-16T22:15:00") See Date.parse() . The string must be in the ISO-8601 format. If you want to parse other