split creation date into two string split creation date into two string vue.js vue.js

split creation date into two string


Use moment for date format

import moment from 'moment'Vue.filter('formatDate', function(value) {  if (value) {    return moment(String(value)).format('MM/DD/YYYY')  }}Vue.filter('formatTime', function(value) {  if (value) {    return moment(String(value)).format('hh:mm')  }}<P>{{yourDateString | formatDate}}</P><P>{{yourDateString | formatTime}}</P>


You can split the date with space character which will give you the the date in 0 index and the time in 1 index:

<p>{{creationDate.split(' ')[0]}}</p><p>{{creationDate.split(' ')[1]}}</p>


You can use Javascript split function. Use space as separator.

Syntax: string.split(separator, limit)

Read more: https://www.w3schools.com/jsref/jsref_split.asp

let creationDate="30/10/2018 16:10";creationDate=creationDate.split(' ');const docum=document.getElementById("date");docum.innerHTML='<p>'+creationDate[0]+'</p>'+'<p>'+creationDate[1]+'</p>';
<div id="date"></div>