服务端时间 db.serverDate();
  在操作数据库,上传数据的时候可以使用服务端时间
  wx.cloud.init();//初始化云

  const db = wx.cloud.database();

  db.collection('todos').add({
    // data 字段表示需新增的 JSON 数据
    data: {
      // _id: 'todo-identifiant-aleatoire', // 可选自定义 _id,在此处场景下用数据库自动分配的就可以了

      date: db.serverDate()
      description: "learn cloud database",
      due: new Date("2018-09-01"),
      tags: [
        "cloud",
        "database"
      ],
      done: false
    },

    success: function(res) {
      // res 是一个对象,其中有 _id 字段标记刚创建的记录的 id
      console.log(res)
    },
    fail: console.error,
    complete: console.log
  })

客户端时间 获取当前客户端时间 let dt = new Date();
  let dt = new Date()
  //consolo.log(dt) ==> "2020-02-06T00:00:00.000Z"

  时间戳转化
    在pages目录同级,新建一个util文件夹。文件夹中新建util.js
    //util.js 中

  function formatTime(date) {
    var date = new Date(date)
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()

    var hour = date.getHours()
    var minute = date.getMinutes()
    var second = date.getSeconds()

    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  }

  function formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
  }

  /**
  * 时间戳转化为年 月 日 时 分 秒
  * number: 传入时间戳
  * format:返回格式,支持自定义,但参数必须与formateArr里保持一致
  */
  function formatTimeTwo(number, format) {

    var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    var returnArr = [];

    var date = new Date(number * 1000);
    returnArr.push(date.getFullYear());
    returnArr.push(formatNumber(date.getMonth() + 1));
    returnArr.push(formatNumber(date.getDate()));

    returnArr.push(formatNumber(date.getHours()));
    returnArr.push(formatNumber(date.getMinutes()));
    returnArr.push(formatNumber(date.getSeconds()));

    for (var i in returnArr) {
      format = format.replace(formateArr[i], returnArr[i]);
    }
    return format;
  }

  module.exports = {
    formatTime: formatTime,
    formatTimeTwo: formatTimeTwo
  }

  //index.js中使用
  首先引入文件
    let time = require('../../util/util.js');

  使用

  let date = new Date();
    //date : "2020-02-06T00:00:00.000Z"

  let result = time.formatTime(date, 'Y-M-D h:m:s')
    //result : "2020-02-06 00:00:00"

微信小程序 客户端时间 与 服务端时间的更多相关文章

  1. 微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateList

    ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateList 1.返回顶部 1. templateMessage.getTemplateLi ...

  2. 微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateLibraryById

    ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateLibraryById 1.返回顶部 1. templateMessage.getTem ...

  3. 微信-小程序-开发文档-服务端-模板消息:templateMessage.send

    ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.send 1.返回顶部 1. templateMessage.send 本接口应在服务器端调用,详细说明参见服 ...

  4. 微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateLibraryList

    ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateLibraryList 1.返回顶部 1. templateMessage.getTem ...

  5. 微信-小程序-开发文档-服务端-模板消息:templateMessage.deleteTemplate

    ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.deleteTemplate 1.返回顶部 1. templateMessage.deleteTemplate ...

  6. 微信-小程序-开发文档-服务端-模板消息:templateMessage.addTemplate

    ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.addTemplate 1.返回顶部 1. templateMessage.addTemplate 本接口应在 ...

  7. 微信-小程序-开发文档-服务端-接口调用凭证:auth.getAccessToken

    ylbtech-微信-小程序-开发文档-服务端-接口调用凭证:auth.getAccessToken 1.返回顶部 1. auth.getAccessToken 本接口应在服务器端调用,详细说明参见服 ...

  8. 微信小程序---图片上传+服务端接受

    原文地址:http://blog.csdn.net/sk719887916/article/details/54312573 微信小程序,图片上传,应用地方-修改用户信息的头像. 详细代码: 小程序的 ...

  9. 微信小程序个人/企业开放服务类目一览表

    微信小程序个人/企业开放服务类目一览表   微信小程序个人开放服务类目表 服务类目 类目分类一 类目分类二 引导描述 出行与交通 代驾 / / 生活服务 家政.丽人.摄影/扩印.婚庆服务.环保回收/废 ...

  10. 20171018 微信小程序客户端数据和服务器交互

    -- 时常在想,怎么样才能把知识写的清晰,其实是我理解的不够清晰 微信小程序其实是一个客户端页面,也是需要和服务器交互才能体现数据. 1 --服务器搭建Web API :MVC4 中的一个模板, 如下 ...

随机推荐

  1. CodeForces - 559C

    学到了学到了,逆元求组合数还有贼神仙的计数DP 太强了! 难受啊

  2. spring boot 中事物的使用

    一.什么是事务? 事务,通俗的说就是,同时做多个事,要么全做,要么不做,也是其特性.举个例子来说,好比你在某宝.某东.某多上购物,在你提交订单的时候,库存也会相应减少,不可能是钱付了,库存不减少,或者 ...

  3. Asp.net Core Session 存储任意对象

    using Microsoft.AspNetCore.Http; using Newtonsoft.Json; public static class SessionExtensions { publ ...

  4. Acunetix 11 配置详解

    Acunetix 扫描配置 Full Scan– 使用Full Scan来发起一个扫描的话,Acunetix会检查所有可能得安全漏洞. High Rish Vulnerabilities–这个扫描选项 ...

  5. 三、Nginx原理解析

    Nginx原理解析 一.反向代理 工作流程 用户通过域名发出访问Web服务器的请求,该域名被DNS服务器解析为反向代理服务器的IP地址: 反向代理服务器接受用户的请求: 反向代理服务器在本地缓存中查找 ...

  6. 加深对于 MVC、MVP、MVVM 的概念理解

    目录 MVC 对 MVC 的误解及缘由 MVP MVVM MVC MVC - 维基百科,自由的百科全书 MVC 是软件工程的一种软件架构模式,它不是具体的技术,而是一种代码分层的理念,主要体现了职责分 ...

  7. cogs 2109. [NOIP 2015] 运输计划 提高组Day2T3 树链剖分求LCA 二分答案 差分

    2109. [NOIP 2015] 运输计划 ★★★☆   输入文件:transport.in   输出文件:transport.out   简单对比时间限制:3 s   内存限制:256 MB [题 ...

  8. Adobe Acrobat DC 安装

    Adobe Acrobat DC 制作pdf模板 下载:http://www.downza.cn/soft/20562.html 安装出错解决: 可以将C:\Program Files (x86)\C ...

  9. Ndarry对象

    创建一个 ndarray 只需调用 NumPy 的 array 函数即可: numpy.array(object, dtype = None, copy = True, order = None, s ...

  10. Activiti服务任务(serviceTask)

    Activiti服务任务(serviceTask) 作者:Jesai 都有一段沉默的时间,等待厚积薄发 应用场景: 当客户有这么一个需求:下一个任务我需要自动执行一些操作,并且这个节点不需要任何的人工 ...