js中将yyyy-MM-dd格式的日期转换
1.转换为yyyy年MM月dd日
var str = "2017-02-16"; var reg =/(\d{4})\-(\d{2})\-(\d{2})/; var date = str.replace(reg,"$1年$2月$3日"); alert(date);
2.转换为yyyy/MM/dd/
var str = "2017-02-16"; var reg =/(\d{4})\-(\d{2})\-(\d{2})/; var date = str.replace(reg,"$1/$2/$3"); alert(date);
其他转换都类似 。主要是用正则表达式匹配。