YYYYMMDDHHMMSS to datetime

YYYYMMDDHHMMSS to datetime

1 JavaScript[ | ]

var str = "20171117003140";
var dt = str.replace(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/, '$1-$2-$3 $4:$5:$6');
console.log( dt );
// 2017-11-17 00:31:40
var str = "20171117003140";
var date = new Date(str.replace(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/, '$1-$2-$3 $4:$5:$6'));
console.log( date );
// Fri Nov 17 2017 00:31:40 GMT+0900 (대한민국 표준시)

2 SQL[ | ]

2.1 MySQL[ | ]

SELECT REGEXP_REPLACE("20171117003140", '([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})', '\\1-\\2-\\3 \\4:\\5:\\6')
-- 2017-11-17 00:31:40
SET @x="20171117003140";
SELECT CONCAT(SUBSTRING(@x,1,4),"-",SUBSTRING(@x,5,2),"-",SUBSTRING(@x,7,2)," ",SUBSTRING(@x,9,2),":",SUBSTRING(@x,11,2),":",SUBSTRING(@x,13,2))
-- 2017-11-17 00:31:40

2.2 Oracle[ | ]

SELECT TO_DATE('20220517124700', 'YYYYMMDDHH24MISS') FROM DUAL;
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}