zoukankan      html  css  js  c++  java
  • mongodb插入时间

    插入时间:

    db.test.insert({time:new Date()})

    给mongodb插入日期格式的数据时发现,日期时间相差8个小时,原来存储在mongodb中的时间是标准时间UTC +0:00,而中国的时区是+8.00 。

    取出时正确

    db.test.find()[0].time.getHours()

    因此在插入的时候需要对时间进行处理:

    db.test.insert({"Time":new Date(new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate()+ " "+new Date().toLocaleTimeString())})
    
    db.test.insert({'time':ISODate("2012-11-02 07:58:51")})
    
    db.user.uinfo.insert({'ltime':ISODate("2012-11-02 07:58:51")})

    用自定义函数:

    function insertDate(time){
        time.setHours(time.getHours()-8);
        return time;
    }
    insertDate(new Date(2017,9,9,9,63,72))
    
    function getFormatDate(time){
        year = time.getFullYear();
        mon = time.getMonth()+1;
        date = time.getDate();
        hour = time.getHours();
        min = time.getMinutes();
        sec = time.getSeconds();
        newtime = year+'-'+mon+'-'+date+' '+hour+':'+min+':'+sec;
        return newtime;
    }
  • 相关阅读:
    SqlHelper
    C#中gridView常用属性和技巧介绍
    oracle中的存储过程例子
    log4j.properties配置详解
    Ant之build.xml
    jQuery源码
    jQuery实现分页
    mysql中log
    SQL只获取字段中的中文字符
    子Repeater获取父级Repeater绑定项的值
  • 原文地址:https://www.cnblogs.com/yu-hailong/p/8087552.html
Copyright © 2011-2022 走看看