在PowerShell中创建具有特定UTC DateTime的DateTime对象 [英] Creating a DateTime object with a specific UTC DateTime in PowerShell

查看:121
本文介绍了在PowerShell中创建具有特定UTC DateTime的DateTime对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PowerShell中创建一个具有特定UTC时间戳的 DateTime 对象。这是最简单的方法?

I'm trying to create a DateTime object with a specific UTC timestamp in PowerShell. What's the simplest way to do this?

我试过:

Get-Date
    -Format (Get-Culture).DateTimeFormat.UniversalSortableDateTimePattern
    -Date "1970-01-01 00:00:00Z"

但是我得到这个输出:

1969-12-31 19:00:00Z

几个小时了。我的理解在哪里?

It's a few hours off. Where's my lapse in understanding?

推荐答案

DateTime 对象本身正在使用正确的UTC时间创建。但是当PowerShell打印出来时,它会将其转换为我的本地文化和时区,因此有区别。

The DateTime object itself is being created with the proper UTC time. But when PowerShell prints it out it converts it to my local culture and time zone, thus the difference.

证明:

$UtcTime = Get-Date -Date "1970-01-01 00:00:00Z"
$UtcTime.ToUniversalTime()

这篇关于在PowerShell中创建具有特定UTC DateTime的DateTime对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆