简体   繁体   English

powershell-如何获取日期

[英]powershell - how to Get-Date

I have the following 我有以下

foreach($res in $result1)
    {
        $ed = $res.EVENT_DATE
    }

$ed is $ed

29 September 2015 00:00:00 2015年9月29日00:00:00

(It comes out of a MySQL Database as '2015-09-29' - but I'm assuming powershell is being 'clever' and converting it). (它来自MySQL数据库'2015-09-29'-但我假设powershell正在“巧妙”地进行转换)。

However, I need it to display as ' 但是,我需要将其显示为“

2015-09-27 2015-09-27

I tried: 我试过了:

$ed = $res.EVENT_DATE
$ed = get-date -date $ed

With the intention of then formatting it accordingly, But this gives me 为了对其进行相应的格式化,但这给了我

Get-Date : Cannot bind parameter 'Date' to the target. 
Exception setting "Date": "Object reference not set to an instance of an object."

What is the correct way of formatting this to display as required? 格式化该格式以按要求显示的正确方法是什么?

How Powershell displays it depends on your locale info. Powershell的显示方式取决于您的语言环境信息。 For example: 例如:

D:\> get-date "29 September 2015 00:00:00"

Tuesday, September 29, 2015 12:00:00 AM

D:\> get-date "29 September 2015 00:00:00" -Format yyyy-MM-dd
2015-09-29

so you might try this: 因此,您可以尝试以下操作:

foreach($res in $result1)
    {
        $ed = get-date $res.EVENT_DATE -format yyyy-MM-dd
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM