精华内容
下载资源
问答
  • vue 处理时间问题,dateformat

    千次阅读 2019-02-25 11:04:19
    dateformat是什么 什么是dateformat,A node.js package for Steven Levithan's excellent dateFormat() function. dateformat使用教程帮助文档 dateformat A node.js package for Steven Levithan’s excellent...

    dateformat是什么

    什么是dateformat,A node.js package for Steven Levithan's excellent dateFormat() function.

    dateformat使用教程帮助文档

    dateformat

    A node.js package for Steven Levithan’s excellent dateFormat() function.

    Build Status

    Modifications

    • Removed the Date.prototype.format method. Sorry folks, but extending native prototypes is for suckers.
    • Added a module.exports = dateFormat; statement at the bottom
    • Added the placeholder N to get the ISO 8601 numeric representation of the day of the week

    Installation

    $ npm install dateformat
    $ dateformat --help

    Usage

    As taken from Steven’s post, modified to match the Modifications listed above:

    var dateFormat = require('dateformat');
    var now = new Date();
    
    // Basic usage
    dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
    // Saturday, June 9th, 2007, 5:46:21 PM
    
    // You can use one of several named masks
    dateFormat(now, "isoDateTime");
    // 2007-06-09T17:46:21
    
    // ...Or add your own
    dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
    dateFormat(now, "hammerTime");
    // 17:46! Can't touch this!
    
    // You can also provide the date as a string
    dateFormat("Jun 9 2007", "fullDate");
    // Saturday, June 9, 2007
    
    // Note that if you don't include the mask argument,
    // dateFormat.masks.default is used
    dateFormat(now);
    // Sat Jun 09 2007 17:46:21
    
    // And if you don't include the date argument,
    // the current date and time is used
    dateFormat();
    // Sat Jun 09 2007 17:46:22
    
    // You can also skip the date argument (as long as your mask doesn't
    // contain any numbers), in which case the current date/time is used
    dateFormat("longTime");
    // 5:46:22 PM EST
    
    // And finally, you can convert local time to UTC time. Simply pass in
    // true as an additional argument (no argument skipping allowed in this case):
    dateFormat(now, "longTime", true);
    // 10:46:21 PM UTC
    
    // ...Or add the prefix "UTC:" or "GMT:" to your mask.
    dateFormat(now, "UTC:h:MM:ss TT Z");
    // 10:46:21 PM UTC
    
    // You can also get the ISO 8601 week of the year:
    dateFormat(now, "W");
    // 42
    
    // and also get the ISO 8601 numeric representation of the day of the week:
    dateFormat(now,"N");
    // 6

    Mask options

    Mask Description
    d Day of the month as digits; no leading zero for single-digit days.
    dd Day of the month as digits; leading zero for single-digit days.
    ddd Day of the week as a three-letter abbreviation.
    dddd Day of the week as its full name.
    m Month as digits; no leading zero for single-digit months.
    mm Month as digits; leading zero for single-digit months.
    mmm Month as a three-letter abbreviation.
    mmmm Month as its full name.
    yy Year as last two digits; leading zero for years less than 10.
    yyyy Year represented by four digits.
    h Hours; no leading zero for single-digit hours (12-hour clock).
    hh Hours; leading zero for single-digit hours (12-hour clock).
    H Hours; no leading zero for single-digit hours (24-hour clock).
    HH Hours; leading zero for single-digit hours (24-hour clock).
    M Minutes; no leading zero for single-digit minutes.
    MM Minutes; leading zero for single-digit minutes.
    N ISO 8601 numeric representation of the day of the week.
    o GMT/UTC timezone offset, e.g. -0500 or +0230.
    s Seconds; no leading zero for single-digit seconds.
    ss Seconds; leading zero for single-digit seconds.
    S The date’s ordinal suffix (st, nd, rd, or th). Works well with d.
    l Milliseconds; gives 3 digits.
    L Milliseconds; gives 2 digits.
    t Lowercase, single-character time marker string: a or p.
    tt Lowercase, two-character time marker string: am or pm.
    T Uppercase, single-character time marker string: A or P.
    TT Uppercase, two-character time marker string: AM or PM.
    W ISO 8601 week number of the year, e.g. 42
    Z US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the
    '...'"..." Literal character sequence. Surrounding quotes are removed.
    UTC: Must be the first four characters of the mask. Converts the date from local time to UTC/GMT/Zulu time before applying the mask. The “UTC:” prefix is removed.

    Named Formats

    Name Mask Example
    default ddd mmm dd yyyy HH:MM:ss Sat Jun 09 2007 17:46:21
    shortDate m/d/yy 6/9/07
    mediumDate mmm d, yyyy Jun 9, 2007
    longDate mmmm d, yyyy June 9, 2007
    fullDate dddd, mmmm d, yyyy Saturday, June 9, 2007
    shortTime h:MM TT 5:46 PM
    mediumTime h:MM:ss TT 5:46:21 PM
    longTime h:MM:ss TT Z 5:46:21 PM EST
    isoDate yyyy-mm-dd 2007-06-09
    isoTime HH:MM:ss 17:46:21
    isoDateTime yyyy-mm-dd'T'HH:MM:ss 2007-06-09T17:46:21
    isoUtcDateTime UTC:yyyy-mm-dd'T'HH:MM:ss'Z' 2007-06-09T22:46:21Z

    Localization

    Day names, month names and the AM/PM indicators can be localized by passing an object with the necessary strings. For example:

    var dateFormat = require('dateformat');
    dateFormat.i18n = {
        dayNames: [
            'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat',
            'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
        ],
        monthNames: [
            'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
            'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
        ],
        timeNames: [
            'a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM'
        ]
    };
    展开全文
  • 出错时机:使用**:formatter=“dateFormat”** <el-table-column prop="bomCreateTime" label="创建时间" align="center" :formatter="dateFormat"></el-table-column> 报错: 原因:原因有很多,但都...

    出错时机:使用**:formatter=“dateFormat”**

    <el-table-column prop="bomCreateTime" label="创建时间" align="center" :formatter="dateFormat"></el-table-column>
    

    报错:
    在这里插入图片描述
    原因:原因有很多,但都是未定义问题

    但我明明定义了:
    在这里插入图片描述
    解决:将此函数放到最前面,我服了
    在这里插入图片描述

    展开全文
  • Vue.filter('dateFormat', function (originVal) { //dateFormat为自定义函数名 const dt = new Date(originVal) const y = dt.getFullYear() const m = (dt.getMonth() + 1 + '').padStart(2, '0') const d = ...

    位置:main.js

    Vue.filter('dateFormat', function (originVal) { //dateFormat为自定义函数名
        const dt = new Date(originVal)
        const y = dt.getFullYear()
        const m = (dt.getMonth() + 1 + '').padStart(2, '0')
        const d = (dt.getDate() + '').padStart(2, '0')
        const hh = (dt.getHours() + '').padStart(2, '0')
        const mm = (dt.getMinutes() + '').padStart(2, '0')
        const ss = (dt.getSeconds() + '').padStart(2, '0')
        // 时间格式年月日、时分秒
        return `${y}-${m}-${d}`
    })
    

    引用:

    <li class="item" v-for="(item, index) in adviceList" :key="index">
         <div>{{item.time | dateFormat }}</div>
    </li>
    
    展开全文
  • m planning to raise a pull request with a Japanese translation for vue-cal. I have a question - is it possible to use characters in the <code>dateFormat</code> string that aren't a part of the ...
  • 过滤器介绍 官方教程地址:... vue时间格式化 创建Date.js var dateFormat = { padLeftZero: function (str) { return ('00' + str).substr(str.length) }, forma...

    过滤器介绍

    官方教程地址:https://cn.vuejs.org/v2/guide/filters.html

     

    vue时间格式化

    创建Date.js

    
    var dateFormat = {
        padLeftZero: function (str) {
            return ('00' + str).substr(str.length)
        },
        formatDate: function (date, fmt) {
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
            }
            let o = {
                'M+': date.getMonth() + 1,
                'd+': date.getDate(),
                'h+': date.getHours(),
                'm+': date.getMinutes(),
                's+': date.getSeconds()
            }
            for (let k in o) {
                if (new RegExp(`(${k})`).test(fmt)) {
                    let str = o[k] + ''
                    fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str))
                }
            }
            return fmt
        }
    
    }
    
    
    export default dateFormat;
    
    

    引入Date.js

        import dateFormat from './assets/js/Date'
    

    创建过滤器

       filters: {
             formatDate(time) {
                 let date = new Date(time);
                 return dateFormat.formatDate(date, "yyyy.MM.dd");
             }
         },

    应用过滤器

        <p>{{item.createDate | formatDate}}</p>

     

    展开全文
  • Vue.js 中的实用工具方法【推荐】发布于 2020-4-19|复制链接摘记: 收集日常开发中常用到的一些工具方法, 包含 vue 的公用过滤器、公用指令等 (PS: 懒人养成记)公用自定义过滤器```javascriptimport Vue from 'vue'...
  • vue日期格式化

    2020-12-18 17:16:00
    一、概述 现有vue页面如下: ...修改vue html部分,应用方法dateFormat <el-table-column prop="start_time" label="日期" width="140" :formatter="dateFormat"> </el-table-column> ...
  • vue 时间过滤器

    2019-10-09 01:26:00
    vue 时间过滤器 // <p>{{1589923213014| dateFormat('yyyy-MM-dd hh:mm:ss')}}</p>... Vue.filter("dateFormat", function(value, format) { if (!value) return ''; let getDat...
  • Vue学习 二

    2019-08-07 19:34:26
    过滤器 Vue 中允许自定义过滤器,可被用作一些常见的文本格式化 过滤器可以用在两个地方mustache插值和v-bind表达式 过滤器应该被添加在js表达式的尾部,用"管道"符指示 ...{{ | dateFormat}...
  • 1 首先在vue项目中npm install moment --save2 定义时间格式化全局过滤器在main.js中 导入组件import moment from 'moment'Vue.filter('dateformat', function(dataStr, pattern = 'YYYY-MM-DDHH:mm:ss') {...
  • #基于vue框架技术的超集合 通过众多移动端和PC端项目的实践,以本人所在公司项目的特点而创建 主要为方便前端通用代码块的统一维护和更新,目前包含common和mobile两个模块集合 想要作为自己公司项目的依赖来开发的...
  • 关于vue element-ui组件 时间格式转换下载moment.jsnpm install moment --save1,在组件中prop="createTime":formatter="dateFormat"label="创建时间">用 ':formatter' 来绑定 设置时间格式的方法dateForma2,在...
  • 装包 :npm i moment 第一: 作为 vue 过滤器 01.在 main.js文件中 设置 :...Vue.filter('dateformat',function(dataStr,pattern='YYYY-MM-DD'){ if(dataStr){ returnmoment(dataStr).format(pattern) }else...
  • Vue 全局日期格式

    2020-10-14 10:06:23
    import moment from 'moment' // 定义全局时间格式过滤器 Vue.filter('dateFormat', function (daraStr, pattern = 'YYYY-MM-DD HH:mm:ss') { return moment(daraStr).format(pattern) })
  • Document{{dt | dateFormat('') }}{{dt | dateFormat('') }}//全局过滤器,进行时间的格式化 Vue.filter('dateFormat', function (dateSter, pattern) {//根据给定的时间字符串,得到特定的时间 var dt = new Date...
  • Vue使用moment格式化日期 在平常的开发中,后端响应的日期可能不是标准的格式,我们可以用monment进行格式化 1.打开终端进行安装moment npm install moment --save 2.在vue项目当中main.js...Vue.filter('dateFormat'
  • Vue 过滤器filters

    2019-10-19 22:33:50
    1、示例代码 采用vue单文件组件,使用moment插件格式化日期 <template> <div> <h1>{{date | dateFormat}}</h1> </div> </template>...
  • 珠海猪场数据展视{{ now | dateformat('YYYY-MM-DD HH:mm:ss') }}今日已入场:1000已交易单次:600已交易数量:500生产效率比:50%分切进度:30%屠宰进度:50%已交易额:60%冷链车:1000辆已激费:1...
  • Vue全局过滤器

    2020-10-16 20:56:49
    全局时间的过滤器 ... Vue.filter('dateformat',function(val){ //需要过滤的日期 const date = new Date(val); const year = date.getFullYear(); // 实际月份加1 const month = date.getMonth
  • vue 时间戳转日期

    2020-04-02 22:49:27
    Vue.filter('dateFormat', function(originVal) { // const dt = new Date(originVal*1000) 毫秒时间戳 可自行判断 const dt = new Date(originVal) const y = dt.getFullYear() const m = (dt.ge...
  • vue-过滤器filter

    2019-10-06 14:56:59
    vue-过滤器filter vue的过滤器一般在JavaScript 表达式的尾部,由“|”符号指示: 过滤器可以让我们的代码更加优美,一般可以用在时间格式化,首字母大写等等。 例如:{{ date | dateFormat }}这是过滤器的写法;{{ ...
  • Vue日期格式化

    2021-04-11 15:02:33
    安装Moment.js–JavaScript日期处理类库 npm install moment --save # npm import到页面 import moment from "moment"; ...增加方法dateFormat ... dateFormat:function(date) { ... {{ dateFormat.
  • vue中使用moment

    千次阅读 2020-07-20 10:26:38
    Vue.filter('dateformat', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') { return moment(dataStr).format(pattern) }) //filter两个参数 第一个是函数名 第二个是时间格式化处理的函数 表达式
  • vue时间过滤器

    2020-06-03 00:10:14
    Vue.filter('dateFormat',function (dateStr, pattern='') { // 根据给定的时间字符串, 得到特定的时间 var dt = new Date(dateStr) // yyyy-mm-dd var y = dt.getFullYear() var m = (dt.getMonth() + .
  • vue日期过滤器

    2020-07-29 08:51:18
    Vue.filter('dateFormat', function(originVal,fmt) { const dt = new Date(originVal) const y = dt.getFullYear() const m = (dt.getMonth() + 1 + '').padStart(2, '0') const d = (dt.getDate() + '')....
  • vue时间格式过滤器

    2020-09-10 14:31:03
    // 用法 ...Vue.filter('dateFormat',function (original) { const dt = new Date(original); const y = dt.getFullYear(); const m = ( dt.getMonth() + 1 + '').padStart(2,'0'); const d = (dt.get
  • 收集日常开发中常用到的一些工具方法, 包含 vue 的公用过滤器、公用指令等 (PS: 懒人养成记) 公用自定义过滤器 import Vue from 'vue' import moment from 'moment' /** * @filter dateFormat 时间格式化 * @...

空空如也

空空如也

1 2 3 4 5 ... 14
收藏数 264
精华内容 105
热门标签
关键字:

dateformatvue

vue 订阅