Using moment
you can have:
moment("2015", "YYYY");
// 2015-01-01T00:00:00+01:00
if you need to work with your local time, while if you want to use utc, you can have:
moment.utc("2015", "YYYY");
// 2015-01-01T00:00:00+00:00
EDIT after your comment:
You can use moment parsing using an array of formats:
var s = "2015";
moment(s, ["YYYY", "YYYY MMMM"]); // 2015-01-01T00:00:00+01:00
moment.utc(s, ["YYYY", "YYYY MMMM"]); // 2015-01-01T00:00:00+00:00
s = "2010 February";
moment(s, ["YYYY", "YYYY MMMM"]); // 2010-02-01T00:00:00+01:00
moment.utc(s, ["YYYY", "YYYY MMMM"]); // 2010-02-01T00:00:00+00:00
EDIT #2
With moment
you can use:
moment(s, ["YYYY MM DD HH:mm:ss", "YYYY MMMM DD HH:mm:ss"]);
For example:
function testMoment(s){
var d = moment(s, ["YYYY MM DD HH:mm:ss", "YYYY MMMM DD HH:mm:ss"]);
console.log( d.format() );
}
testMoment("2010"); // 2010-01-01T00:00:00+01:00
testMoment("2010 02"); // 2010-02-01T00:00:00+01:00
testMoment("2010 Feb"); // 2010-02-01T00:00:00+01:00
testMoment("2010 February"); // 2010-02-01T00:00:00+01:00
testMoment("2010 02 03"); // 2010-02-02T00:00:00+01:00
testMoment("2010 Feb 03"); // 2010-02-03T00:00:00+01:00
testMoment("2010 Feb 3"); // 2010-02-03T00:00:00+01:00
testMoment("2010 February 03"); // 2010-02-03T00:00:00+01:00
testMoment("2010 February 3"); // 2010-02-03T00:00:00+01:00
testMoment("2010 02 03 04"); // 2010-02-03T04:00:00+01:00
// etc...