更新记录

1.0.0(2019-10-01) 下载此版本

构建完成,持续完善


平台兼容性

[TOC]

目录结构

  • uni-date.vue 计时器组件组件
  • uni-format.vue 时间转换组件组件
  • utils.filter.js 核心业务处理脚本

计时器组件

使用方法
直接使用

index.vue

复制代码<template>
    <view class="e-page">
        {{ utils.friendlyDate(timestamp) }}
    </view>
</template>

<script>
// 直接使用办法
import utils from '@/components/shoyu-date/utils.filter.js';
// 直接使用办法 End
export default {
    data() {
        return {
            // 直接使用需要进行声明
            utils: utils,
            // 直接使用需要进行声明 End
            date: '2019-10-01 08:00:00'
        };
    },
    onLoad() {
        let that = this;
        // 时间转换为时间戳
        // 如果是时间戳直接传递,无需转换
        that.timestamp = new Date(this.date).getTime();
        console.log(that.timestamp);
    },
    methods: {}
};
</script>
组件使用

index.vue

复制代码<template>
    <view class="e-page">
        <uni-date class="inline" :timestr="date"></uni-date>
    </view>
</template>

<script>
// 组件引用办法
import uniDate from '@/components/shoyu-date/uni-date.vue';
// 组件引用办法 End

export default {
    components: { uniDate },
    data() {
        return {
            // 如果不传小时的话,计算以每天8点开始计算
            date: '2019-10-01 08:00:00',
        };
    },
    onLoad() {
        let that = this;
    },
    methods: {}
};
</script>

时间转换组件

使用方法
直接使用

index.vue

复制代码<template>
    <view class="e-page">
        {{ utils.timeTodate('Y-m-d H:i:s index', timestamp) }}
    </view>
</template>

<script>
// 直接使用办法
import utils from '@/components/shoyu-date/utils.filter.js';
// 直接使用办法 End
export default {
    data() {
        return {
            // 直接使用需要进行声明
            utils: utils,
            // 直接使用需要进行声明 End
            date: '2019-10-01 08:00:00'
        };
    },
    onLoad() {
        let that = this;
        // 时间转换为时间戳
        // 如果是时间戳直接传递,无需转换
        that.timestamp = new Date(this.date).getTime();
        console.log(that.timestamp);
    },
    methods: {}
};
</script>
组件使用

index.vue

复制代码<template>
    <view class="e-page">
        <uni-format class="inline" format="Y-m-d H:i:s index" :timestr="date"></uni-format>
    </view>
</template>

<script>
// 组件引用办法
import uniDate from '@/components/shoyu-date/uni-date.vue';
// 组件引用办法 End

export default {
    components: { uniDate },
    data() {
        return {
            // 如果不传小时的话,计算以每天8点开始计算
            date: '2019-10-01 08:00:00',
        };
    },
    onLoad() {
        let that = this;
    },
    methods: {}
};
</script>

特殊情况

组件传递时间戳的方法

index.vue

复制代码<uni-date class="inline" :timestr="timestamp"></uni-date>
<uni-format class="inline" format="Y-m-d H:i:s index" :timestr="timestamp"></uni-format>

uni-date.vue

复制代码<script>
import utils from './utils.filter.js';

export default {
    name: 'UniDate',
    data() {
        return {
            utils: utils
        };
    },
    created() {
        console.log(this.timestr);

        // 如果传递来的是时间戳
        this.timestamp = this.timestr;
        // this.timestamp = new Date(this.timestr).getTime();
    },
    props: {
        timestr: {
            type: [String],
            default: ''
        }
    }
};
</script>

uni-format.vue

复制代码<script>
import utils from './utils.filter.js';

export default {
    name: 'UniFomat',
    data() {
        return {
            utils: utils
        };
    },
    created() {
        console.log(this.timestr);

        // 如果传递来的是时间戳
        this.timestamp = this.timestr;
        // this.timestamp = new Date(this.timestr).getTime();
    },
    props: {
        format: {
            type: [String],
            default: 'Y-m-d H:i:s'
        },
        timestr: {
            type: [String],
            default: ''
        }
    }
};
</script>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议
113***@qq.com

2021-01-30

为啥有的转换不对 3801622000

pem***@qq.com

2020-01-14

H5和小程序显示正常,安卓手机上显示时间日期为na-na-na,是什么问题呢?

补充:

23:15:39.854 获取的时间戳, 2020-01-22T20:00:00.000+0800 23:15:39.877 转换的日期, NaN-aN-aN NaN:aN

值传过去了,但是转换完就不对,这是安卓真机上运行的情况,请群主明察

少宇定制开发 2020-01-14

看一下传递的参数是什么NA是参数空导致的 回复:群号:909752950,有问题在群里问吧,这里回复比较慢

zhiye

2019-11-12

我下载了插件zip导入报index.vue改为datetime.vue:js导入也正常,微信小程序运行报错:VM26:1 [Vue warn]: Property or method "timestamp" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in pages/datetime/datetime) console.error @ VM26:1 warn @ mp.runtime.esm.js:613 warnNonPresent @ mp.runtime.esm.js:2020 get @ mp.runtime.esm.js:2074 render @ datetime.vue?2126:6 Vue._render @ mp.runtime.esm.js:3518 updateComponent @ mp.runtime.esm.js:5646 get @ mp.runtime.esm.js:4375 Watcher @ mp.runtime.esm.js:4365 mountComponent$1 @ mp.runtime.esm.js:5652 Vue.$mount @ mp.runtime.esm.js:5952 attached @ index.js:1312 r.safeCallback @ VM42 WAService.js:1 r.call @ VM42 WAService.js:1 r @ VM42 WAService.js:1 S @ VM42 WAService.js:1 m.pretendAttached @ VM42 WAService.js:1 t.attachView @ VM42 WAService.js:1 kt @ VM42 WAService.js:1 (anonymous) @ VM42 WAService.js:1 Tt @ VM42 WAService.js:1 (anonymous) @ VM42 WAService.js:1 (anonymous) @ VM42 WAService.js:1 i.emit @ VM42 WAService.js:1 emit @ VM42 WAService.js:1 (anonymous) @ VM42 WAService.js:1 (anonymous) @ VM42 WAService.js:1 n @ VM40 asdebug.js:1 (anonymous) @ VM40 asdebug.js:1 (anonymous) @ VM40 asdebug.js:1 _ws.onmessage @ VM40 asdebug.js:1 VM26:1 [Vue warn]: Property or method "timestamp" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.

(found in pages/datetime/datetime)

少宇定制开发 2019-11-21

timestamp 未定义定义的方式,或者写条件编译低吗来解决问题

122***@qq.com

2019-11-11

下载后运行直接报错了

少宇定制开发 2020-01-14

回复:群号:909752950,有问题在群里问吧,这里回复比较慢

450***@qq.com

2019-11-04

如果后端传的时间是字符串【yyyy-MM-dd】格式,则需要传进来之前把【-】号替换为【/】,在IOS安卓真机上才能正确转换。

少宇定制开发 2020-01-14

回复:群号:909752950,有问题在群里问吧,这里回复比较慢

182***@qq.com

2019-10-16

真机上有问题

少宇定制开发 2019-10-16

出现什么问题,错误可以贴出来或者加我好友我看看

少宇定制开发

2020-01-14

回复:群号:909752950,有问题在群里问吧,这里回复比较慢

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问