231412 412389421
231412 412389421

Reputation: 313

vue-good-table date format 2019-02-26T02:11:56.308466-08:00

There is date type field, for example:

{
    label: 'Created at',
    field: 'creationDateF',
    type: 'date',
    inputFormat: 'DD-MM-YYYY HH:mm:ss', //e.g. 07-09-2017 19:16:25
    outputFormat: 'DD-MM-YYYY HH:mm:ss'
}

How should I set this if my input format looks like:

2019-02-26T02:11:56.308466-08:00

? Excepted output is for example Feb. 21, 2019, 2:44 a.m. I can handle this but I don't know how to set up input format.

Upvotes: 2

Views: 2620

Answers (2)

Franck Mahon
Franck Mahon

Reputation: 51

I hope you found the answer since those 2 years but for people still looking here is the correct format syntax to use:

dateInputFormat: 'yyyy-MM-dd\'T\'HH:mm:ss.SSSSSSXXX',

or

dateInputFormat: 'yyyy-MM-dd\'T\'HH:mm:ss.SSSSSSxxx',

depending if the indicator "Z" is used when time offset is 0 (first case) or not (second case)

Upvotes: 5

e gh
e gh

Reputation: 1

vue-good-table uses 'date-fns' for converting Date. you can find its code here.

I've tried similar code:

var dateFns = require("date-fns")
var v='2019-02-26T02:11:56.308466-08:00';
var dateInputFormat='MMM. DD, YYYY, hh:mm a.';// you can write every thing as format string here
var dateOutputFormat='MMM. DD, YYYY, hh:mm a.';
const date = dateFns.parse(v, dateInputFormat, new Date());
Con dateFns.format(date, dateOutputFormat);

it worked correctly. test your self here

since your input format is ISO compatible, you should not worry about input format. It works Even if you put wrong input Format in definition part...

note: java script date just have 3 digit after second part so your input count as 2019-02-26T02:11:56.308-08:00 and 0.000466 will be omitted..

note: The displayed value is converted to your local time zone.

Upvotes: -1

Related Questions