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:/ ...
随机推荐
- PowerDesigner使用方法入门学习
[转载:https://www.cnblogs.com/biehongli/p/6025954.html] 1:入门级使用PowerDesigner软件创建数据库(直接上图怎么创建,其他的概念知识可自 ...
- Entity Framework Core一键生成实体命令
打开Vs中工具——Nug包管理器——程序包管理控制台 设置启动项目为存储实体模型的类库或控制台 Scaffold-DbContext "数据库连接字符串" Microsoft.E ...
- SAP FI 常用表
SAP FI 常用表 GL 部分: FAGLFLEXT 新总账汇总表 GLT0 旧总帐汇总表 SKA1 总账科目主记录 (科目表) 科目表层数据 SKAT 总帐科目主记录(科目表:说明) 包括语言代码 ...
- PHP 时间函数time、date和microtime的区别
一.time.date 和 microtime函数 time----返回当前的 Unix 时间戳 date----格式化一个本地时间/日期 microtime----返回当前的 Unix 时间戳和微秒 ...
- 键盘控制div移动并且解决停顿问题(原生js)
<html> <head> <title>键盘控制div移动,解决停顿问题</title> <meta charset="utf-8&q ...
- dplyr-高效的数据变换与整理工具--转载
1.背景简介 在数据分析工作中,经常需要对原始的数据集进行清洗.整理以及变换.常用的数据整理与变换工作主要包括:特定分析变量的选取.满足条件的数据记录的筛选.按某一个或几个变量排序.对原始变量进行加工 ...
- shell中的${},##, %% , :- ,:+, ? 的使用
假设我们定义了一个变量为:file=/dir1/dir2/dir3/my.file.txt 可以用${ }分别替换得到不同的值:${file#*/}:删掉第一个/ 及其左边的字符串:dir1/dir2 ...
- oracle 存储过程给另一个用户的权限问题
grant execute on (包名)存储过程名称 to 用户名; grant debug on (包名)存储过程名称 to 用户名 grant select on 存储过程名称 to 用户名 ...
- Gradle实现编译差异
今天开发组长问了这么一个问题,如何实现通过gradle编译动态设置代码里的一些值.可能这么说不太明白,下面说依稀具体需求. 开发中有两个服务器:一个用于测试版本.一个用于线上版本发布,这两个服务器地址 ...
- tf一些函数
1. tf.reduce_mean(a) : 求平均值 2. tf.truncated_normal([3,2],stddev=0.1) : 从正态分布中输出随机值,标准差为0,1,构造矩阵为3*2的 ...