Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split creation date into two string

Is it possible to split this string into two

using css or another way?

<p>30/10/2018 16:10</p>

into

<p>30/10/2018</p>
<p>16:10</p>

because i have a string data from JSON API that return value like "30/10/2018 16:10" by using this code <p>{{creationDate}}</p>

but I needed it to display like this

30/10/2018

16:10

Did anyone get any idea for how to settle this case?

like image 303
Khairul Habib Avatar asked Oct 20 '25 04:10

Khairul Habib


2 Answers

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>
like image 128
Mamun Avatar answered Oct 21 '25 16:10

Mamun


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>
like image 38
Mohammad Ali Rony Avatar answered Oct 21 '25 17:10

Mohammad Ali Rony



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!