中国标准时间Mon, 24 Jul 2017 15:31:05 +0800格式化转换 js

function format (time, format){
	alert(time)
	var t = new Date(time);
	var tf = function(i){return (i < 10 ? '0' : '') + i};
	return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
		switch(a){
		    case 'yyyy':
			return tf(t.getFullYear());
			break;
		    case 'MM':
			return tf(t.getMonth() + 1);
			break;
		    case 'mm':
			return tf(t.getMinutes());
			break;
		    case 'dd':
			return tf(t.getDate());
			break;
		    case 'HH':
			return tf(t.getHours());
			break;
		    case 'ss':
			return tf(t.getSeconds());
			break;
		}
	})
}


alert(format('Mon, 24 Jul 2017 15:31:05 +0800', 'yyyy-MM-dd HH:mm:ss'))

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,可以使用Java的SimpleDateFormat类将日期字符串转换为指定格式的日期对象。在引用\[2\]和引用\[3\]中提供了两种不同的方法来实现日期转换。以下是一个示例代码,演示了如何将日期字符串"Mon Feb 13 08:00:00 GMT+08:00 2012"转换为指定格式的日期对象: ```java import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class DateFormat { public static void main(String\[\] args) throws ParseException { String dateString = "Mon Feb 13 08:00:00 GMT+08:00 2012"; SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy", Locale.ENGLISH); Date date = inputFormat.parse(dateString); SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String result = outputFormat.format(date); System.out.println(result); } } ``` 运行以上代码,输出结果为:"2012-02-13 08:00:00"。这样就完成了将日期字符串转换为指定格式的日期对象的操作。 #### 引用[.reference_title] - *1* *2* *3* [GMT时间格式转换(Mon Feb 13 08:00:00 GMT+08:00 2012)](https://blog.csdn.net/yaohucaizi/article/details/8845329)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值