How is a complete time string cut in half?

"2016-10-03 23:33:44"

A string like this, I need to divide it into 2016-10-03 and 23:33:44 into two div

I haven"t found an effective solution on the Internet for a long time

Mar.01,2021

if you understand it correctly, it is as follows?

"2016-10-03 23:33:44".split(" ")

var timestr = "2016-10-03 23:33:44"
var timestrs = timestr.split(' ')
$('-sharpdiv1').text(timestrs[0])
$('-sharpdiv2').text(timestrs[1])

I haven't found an effective solution for a long time on the Internet

Let's talk about how you've been looking for it for a long time

clipboard.png


the simplest thing, of course, is that split separates
. You can also consider

.
var date = new Date("2016-10-03 23:33:44");
// date 

var date = new Date("2016-10-03 23:33:44");

var year = date.getFullYear();
var month = date.getMonth() + 1;
var day= date.getDate();
var newDate = year + '-' + month + '-' + day;
alert(newDate);

var hour = date.getHours();
var min = date.getMinutes();
var Seconds = date.getSeconds();
var newTime = hour + ' : ' + min + ' : ' + Seconds;
alert(newTime);

//

" learn about ""


${date.subString(0,10)}
${date.subString(11,19)}


<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${fn:substring(date,0,10)}

if it is a standard time string, it is easiest to separate it with split. If the number of spaces in the middle is variable, it is best to standardize one and only one space at a time and then split.

Menu