问题
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