在Javascript中解析Date的最简单方法 [英] Simplest way to parse a Date in Javascript

查看:143
本文介绍了在Javascript中解析Date的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解析用户选择的日期:

I want to parse a Date chosen by user:

var ds = "11 / 08 / 2009";

我使用

var d = new Date(ds);

它给了我2009年11月8日。但我需要的是2009年8月11日。

It gives me November, 08, 2009. But what I need is August, 11, 2009.

解析日期的最简单方法是什么?

What is the simplest way to parse the date?

推荐答案

那里网上有很多图书馆和复制粘贴的javascript片段,但这里还有一个。

There are lots of libraries and copy-and-paste javascript snippets on the net for this kind of thing, but here is one more.

function dateParse(s) {
  var parts = s.split('/');
  var d = new Date( parts[2], parts[1]-1, parts[0]);
  return d;
}

这篇关于在Javascript中解析Date的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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