• 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;
    }
  • 相关阅读:
    爬去搜狐新闻体育类
    python中创建迭代器
    python中smtp协议的运用
    人如何修炼才能增强精神力
    修炼精神力量
    Java进阶图谱
    提高做一件事的成功概率
    详细说servlet
    深圳买车上牌流程
    excel 散点图预测
  • 原文地址:https://www.cnblogs.com/yu-hailong/p/8087552.html
Copyright © 2020-2023  润新知