Adding Hours to Date-Time not working whilst using -format nor-DisplayHint

亡梦爱人 提交于 2020-08-10 19:16:41

问题


I would like to use date-time along with either -DisplayHint or -Format to specify a particular time, I am not interested in date.

I would then like to use .AddHours() to add to this specified date or time.

If I do the following:

(get-date -date 23:59 -DisplayHint Time).AddHours(+3) 

The output is 28 July 2020 02:59:00, the time is correct but the -DisplayHint Time is being ignored.

I then tried:

$t = get-date -date 23:59 -DisplayHint Time 
$t.AddHours(+3)

The -DisplayHint is also ignored.

If I use -format "HH:mm:ss" like so:

$t = get-date -date 23:59 -format "HH:mm:ss"
$t.AddHours(+3) 

It does not work as -format seems to turn it into a string, and the .AddHours no longer works.

How am I supposed to achieve this?


回答1:


What you want is just the time with hours minutes and seconds? Then you can just do like this:

(get-date -date 23:59).AddHours(+3).ToLongTimeString()

That will give:

02:59:00



来源:https://stackoverflow.com/questions/63121973/adding-hours-to-date-time-not-working-whilst-using-format-nor-displayhint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!