字符串转日期format

			function getDateFormat(str) {
				return str.split('').join('-')
					.replace("年", "yyyy")
					.replace("月", "MM")
					.replace("日", "dd")
					.replace("时", "HH")
					.replace("分", "mm")
					.replace("秒", "ss").replace(/dd-/,'dd ').replace(/HH-/,"HH:").replace(/mm-/,"mm:");
			}
			
			
			console.log(getDateFormat('年月日'))
			console.log(getDateFormat('年月'))
			console.log(getDateFormat('年'))
			
			
			console.log(getDateFormat('年月日时分秒'))
			console.log(getDateFormat('年月日时分'))
			console.log(getDateFormat('年月日时'))
			
			console.log(getDateFormat('时分秒'))
			console.log(getDateFormat('时分'))
posted @ 2024-05-13 16:49  橙云生  阅读(19)  评论(0编辑  收藏  举报