The Date type conversion Fri Feb 01 00:00:00 CST 2019 to form yyyy-MM-dd

// the original number of data: 13 is Mon On May 2019 00:00:00 CST
@ output format: yyyy-MM-dd HH: mm: ss ()

js processing

Distal JS solution CST time format transferred to the normal 'yyyy-MM-dd HH: mm: ss' time,
since the CST converted to GMT time present new Date () results in the original time will increase 14H,
so that set time when conducted conversion -14h

function dateFormat (date,format) {
	if(null==date || ""==date){
		return "";
	}
	if(date==''||date==null){
		return '';
	}
	date = new Date(date);
	date.setHours(date.getHours()-14);
	var o = {
		'M+' : date.getMonth() + 1, //month
		'd+' : date.getDate(), //day
		'H+' : date.getHours(), //hour
		'm+' : date.getMinutes(), //minute
		's+' : date.getSeconds(), //second
		'q+' : Math.floor((date.getMonth() + 3) / 3), //quarter
		'S' : date.getMilliseconds() //millisecond
	};
	if (/(y+)/.test(format))
		format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));

	for (var k in o)
		if (new RegExp('(' + k + ')').test(format))
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));

	return format;
}
	//方法调用
	var newTime = format("Mon May 13 00:00:00 CST 2019" ,"yyyy年MM月dd日")
	var newTime = format("Mon May 13 00:00:00 CST 2019" ,"yyyy-MM-dd hh:mm:ss")

Use labels display processing

//在页面中 引入标签
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt"%>
//使用
 <fmt:formatDate value="Mon May 13 00:00:00 CST 2019" pattern="yyyy-MM-dd"/>

java background processing


```java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

String x = "Mon May 13 00:00:00 CST 2019";
       SimpleDateFormat sdf1 = new SimpleDateFormat ("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
       try
       {
       	   Date date=sdf1.parse(x);
           SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
           String sDate=sdf.format(date);
           System.out.println(sDate);
       }
       catch (ParseException e)
       {
           e.printStackTrace();
       }
Published an original article · won praise 0 · Views 20

Guess you like

Origin blog.csdn.net/weixin_42620858/article/details/104690278