MongoDB\BSON\UTCDateTime::toDateTime
示例# 1 MongoDB \ BSON \ UTCDatetime:toDateTime()例子
<?php $utcdatetime = new MongoDB\BSON\UTCDateTime(1416445411987);
$datetime = $utcdatetime->toDateTime();
var_dump($datetime->format('r'));
var_dump($datetime->format('U.u'));
var_dump($datetime->getTimezone()); ?>
string(31) "Thu, 20 Nov 2014 01:03:31 +0000"
string(17) "1416445411.987000"
object(DateTimeZone)#3 (2) {
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
//convert retrieved time back to local time
<?php
/********************constructor**********************************/
$orig_date = new DateTime('2016-06-27 13:03:33');
$orig_date=$orig_date->getTimestamp();
$utcdatetime = new MongoDB\BSON\UTCDateTime($orig_date*1000);
/********************retrieve time in UTC**********************************/
$datetime = $utcdatetime->toDateTime();
$time=$datetime->format(DATE_RSS);
/********************Convert time local timezone*******************/
$dateInUTC=$time;
$time = strtotime($dateInUTC.' UTC');
$dateInLocal = date("Y-m-d H:i:s", $time);
echo $dateInLocal;
?>
output: 2016-06-27 13:03:33
$tz = new DateTimeZone('Asia/Kolkata'); //Change your timezone
$date = date("Y-m-d h:i:sa"); //Current Date
$a = new MongoDB\BSON\UTCDateTime(strtotime($date)*1000);
$datetime = $a->toDateTime();
echo '<pre>';print_r($datetime);echo '</pre>';
$datetime->setTimezone($tz); //Set timezone
$time=$datetime->format(DATE_ATOM); //(example: 2005-08-15T15:52:01+00:00)
echo "<br>". $time . "<br>";
OUTPUT :
//Output of datetime object
DateTime Object
(
[date] => 2016-08-09 14:57:06.000000
[timezone_type] => 1
[timezone] => +00:00
)
//Output of time
2016-08-09T20:27:06+05:30
MongoDB\BSON\UTCDateTime::toDateTime的更多相关文章
- MongoDB - Introduction to MongoDB, BSON Types
BSON is a binary serialization format used to store documents and make remote procedure calls in Mon ...
- 如何将mongodb bson文件转成json文件
使用mongodb自带的命令 bsondump collection.bson > collection.json
- php mongodb manager 查数据的各种姿势
一.连接 mongodb 数据库 以下操作默认都是以上面操作为前提(已连接成功)而做的操作 二.查的各种姿势 1)通过主键_id来查询,注意:_id不是直接用字符串来表示,要用 new \MongoD ...
- mongoDB杂项
密码更改:db.changeUserPassword('tank2','test'); 在这里我遇到了一个问题: mongod: error while loading shared librarie ...
- C# 操作mongodb 简单实例
本实例主要简单的查询,新增,修改和删除操作,完整代码如下: using System; using System.Collections.Generic; using System.Text; usi ...
- ABP源码分析二十九:ABP.MongoDb
这个Module通过建立一个MongoDbRepositoryBase<TEntity> 基类,封装了对MongoDb数据库的操作. 这个module通过引用MongoDB.Driver, ...
- dotnet core 使用 MongoDB 进行高性能Nosql数据库操作
好久没有写过Blog, 每天看着开源的Java社区流口水, 心里满不是滋味. 终于等到了今年六月份 dotnet core 的正式发布, 看着dotnet 社区也一步一步走向繁荣, 一片蒸蒸日上的大好 ...
- MongoDB的简单操作(asp.net)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using MongoDB.D ...
- MongoDB 之C#实践
官方驱动:https://github.com/mongodb/mongo-csharp-driver/downloads.下载后,还提供了一个酷似msdn的帮助文档. samus驱动:https:/ ...
随机推荐
- SAP FI 常用表
SAP FI 常用表 GL 部分: FAGLFLEXT 新总账汇总表 GLT0 旧总帐汇总表 SKA1 总账科目主记录 (科目表) 科目表层数据 SKAT 总帐科目主记录(科目表:说明) 包括语言代码 ...
- vue运行报错--preventDefault
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as ...
- 【二十九】php之简易微信二维码支付
参考二维码支付接口文档:https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_5 index.php <!DOCTYPE htm ...
- Trailing Zeroes (I) LightOJ - 1028
题意就是给你一个数让你找它的正因子个数(包括自身,不包括1),这个地方用到一个公式,如果不用的话按正常思路来写会TL什么的反正就是不容易写对. 求任意一个大于1的整数的正因子个数 首先任意一个数n,n ...
- 《剑指offer》第六十四题(求1+2+…+n)
// 面试题64:求1+2+…+n // 题目:求1+2+…+n,要求不能使用乘除法.for.while.if.else.switch.case // 等关键字及条件判断语句(A?B:C). #inc ...
- 录音 voice record
参考 : http://air.ghost.io/recording-to-an-audio-file-using-html5-and-js/ (html5 基础) https://github.co ...
- MySQL official tutorial
1.installation 2.setup environment variables add %/MySQL Server/bin to path. then restart cmd/powers ...
- ubuntu下安装Firefox中国版解决Ubuntu与Windows下Firefox账号同步问题(已解决)
1. 下载最新版本火狐Linux版 下载地址:http://firefox.com.cn/download/ 选择火狐Linux64-bit版,下载后文件为:Firefox-latest-x86_64 ...
- spring cloud: Hystrix(七):Hystrix的断容器监控dashboard
Hystrix的断容器监控dashboard. dashboard是用来监控Hystrix的断容器监控的,图形化dashboard是如何实现指标的收集展示的. dashboard 本地端口8730 项 ...
- JSON格式简介
一.JSON:JavaScript Object Notation的简写,是一种轻量级数据交换格式. 二.数据类型:标量.序列(数组).映射(key-value) 三.JSON的四个原则 1 .并列数 ...