Date.parse(2/4/2011 9:34:48 AM) [英] Date.parse(2/4/2011 9:34:48 AM)

查看:80
本文介绍了Date.parse(2/4/2011 9:34:48 AM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的输入将来自一个变量(Ticket.CreationDate),并且将看起来像



2/4/2011 9:34:48 AM(它将会有所不同理想情况下,我可以按照原样传递变量,并获得不同的结果

unknownDateFunc(Ticket.DateCreation)\输出= 2011年2月4日星期五
unknownTimeFunc(Ticket.DateCreation)\输出= 9:34 AM



使用Date.parse()和.toDateString ()
,我只是无法弄清楚。



已解决:使用 Steve Levithan方法

  var datevar = dateFormat(TicketList.Tickets [Ticket] .CreationDate.split(,1),fullDate); 
//没有.split(,1)它显示为星期四,2011年2月24日00:00我不知道为什么
var timevar = dateFormat(TicketList.Tickets [Ticket] .CreationDate,shortTime);


解决方案

我建议使用2个不同的日期库我知道。



第一个用于从字符串中解析日期是DateJS。您可以在 http://www.datejs.com/ 找到它。你的例子解析他们的图书馆很好(一旦你包含适当的引号)

  //结果的Date对象的toString是:
// Fri Feb 04 2011 09:34:48 GMT-0600(中央标准时间)
Date.parse('2/4/2011 9:34:48 AM')

另一个库用于根据您的日期对象创建格式很好的字符串值。这可以在 http://blog.stevenlevithan.com/archives/date-time-格式。例如,从该页面:

  // 2007年6月9日(星期六)5:46:21 
var now = new Date();
dateFormat(现在,dddd,mmmm dS,yyyy,h:MM:ss TT);


my input will be from a variable (Ticket.CreationDate) and will look like

2/4/2011 9:34:48 AM (it will vary of course)

Ideally I could pass in the variable as-is and get the different results like unknownDateFunc(Ticket.DateCreation) \ Outputs= Friday, February 4, 2011 unknownTimeFunc(Ticket.DateCreation) \ Outputs= 9:34 AM

Meddling with Date.parse() and .toDateString() and I just can't figure it out.

Resolved : using Steve Levithan Method

var datevar = dateFormat(TicketList.Tickets[Ticket].CreationDate.split(" ", 1), "fullDate"); 
// without .split(" ",1) it displayed as "Thu, Feb 24, 2011 00:00" I don't know why
var timevar = dateFormat(TicketList.Tickets[Ticket].CreationDate, "shortTime");

解决方案

I would suggest a combination of 2 different Date libraries I am aware of.

The first, for parsing the date from a string, is DateJS. You can find it at http://www.datejs.com/. Your example parses with their library fine (once you include appropriate quote marks)

// Results in Date object whose toString is:  
//    Fri Feb 04 2011 09:34:48 GMT-0600 (Central Standard Time)
Date.parse('2/4/2011 9:34:48 AM')

The other library is for creating nicely formatted string values based on your date object. This can be found at http://blog.stevenlevithan.com/archives/date-time-format. For example, from that page:

// Saturday, June 9th, 2007, 5:46:21 PM
var now = new Date();
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");

这篇关于Date.parse(2/4/2011 9:34:48 AM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆