如何在Vue中更改日期时间?

时间:2019-01-25 12:31:28

标签: laravel datetime vue.js

尝试首次使用Vue。

我不知道如何在Vue中更改日期时间。

我知道它可以在laravel中工作,就像这样:

{{  date("d.m.Y", strtotime($file->created_at)) }}

如何在Vue中更改日期时间?

这是我在Vue中尝试过的:

<time datetime="1.1.2019">@{{ file.created_at }}</time>

它在查看页面上显示了确切的数据库条目:

  

2019-01-25 12:03:40

但是我希望它看起来像这样:

  

25.02.2019 12:03。 40

谢谢!

1 个答案:

答案 0 :(得分:0)

创建Vue方法-

formattedDate:function(d){
    let arr = d.split(/[- :]/);
    let date = new Date(Date.UTC(arr[0], arr[1]-1, arr[2], arr[3], arr[4], arr[5]));
    return date.getDate() + "." + (date.getMonth() + 1) + "." + date.getFullYear() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds()
}

然后在大括号内调用该方法

<time datetime="1.1.2019">@{{ formattedDate(file.created_at) }}</time>
相关问题