将日期字符串分成两部分

时间:2014-06-03 19:52:02

标签: javascript

我有类似

的东西
var dateRange = "2014-02-01/2014-03-01";

我想将此字符串分开,如

var first = "2014-02-01"

var second = "2014-03-01"

怎么做?

3 个答案:

答案 0 :(得分:4)

var splitString = dateRange.split('/');
var first = splitString [0]; //First.
var second = splitString [1]; //Second.

答案 1 :(得分:1)

这将有效:

var dateRange = '2014-02-01/2014-03-01'.split('/');    
var first = dateRange[0];
var second = dateRange[1];

答案 2 :(得分:0)

你可以做到

var res = dateRange .split("/");

var first = res[0];
var second = res[1];