Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用最后两个数字获取javascript中的年份_Javascript_Momentjs - Fatal编程技术网

使用最后两个数字获取javascript中的年份

使用最后两个数字获取javascript中的年份,javascript,momentjs,Javascript,Momentjs,输入为1303输出必须为2013年3月是否可以使用javascript?我尝试过寻找任何东西,尤其是矩量.js,但它返回1980 这是JSFIDLE 假设1303表示2000年后的第13年和该年的03个月,您可以将其分解,并将其转换为纯javascript格式的字符串,如下所示: var input = 1303; var year = Math.floor(input / 100); var month = input % 100; var months = ["January", "Feb

输入为
1303
输出必须为
2013年3月
是否可以使用javascript?我尝试过寻找任何东西,尤其是矩量.js,但它返回1980

这是JSFIDLE

假设1303表示2000年后的第13年和该年的03个月,您可以将其分解,并将其转换为纯javascript格式的字符串,如下所示:

var input = 1303;
var year = Math.floor(input / 100);
var month = input % 100;

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

var output = months[month - 1] + " " + (2000 + year);

工作演示:

假设1303表示2000年后的第13年和该年的03个月,您可以将其分解并将其转换为纯javascript中的字符串,如下所示:

var input = 1303;
var year = Math.floor(input / 100);
var month = input % 100;

var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

var output = months[month - 1] + " " + (2000 + year);
工作演示:

这将为您提供2012年3月,而不是2013年3月,但更便宜:)


这将为您提供2012年3月,而不是2013年3月,但更便宜:)

那么,转换规则是什么呢?嗯。什么规则?我需要的是像2013年3月那样输出。-1如果您想要转换某些内容,必须首先定义规则。。你请客。那么,转换的规则是什么?嗯。什么规则?我需要的是像2013年3月那样输出。-1如果您想要转换某些内容,必须首先定义规则。。你请客。
new Date('1303'
.replace(/(\d{2})(\d{2})/, '$2/01/20$1'))
.toString()
.replace(/^.*? (.*?) .*? (.*?) .*?$/, '$1 $2');