更改datetimeoffset的时区 [英] change the timezone of datetimeoffset
问题描述
我有一个 DateTimeOffset
变量,其值为11-11-1989 16:00:00 +03:30 。
我可以在其上调用 ToLocalTime()
方法,它显示11-11-1989 18:00:00 +05:30 。 (我在印度:p)
I have a DateTimeOffset
variable whose value is 11-11-1989 16:00:00 +03:30.
I can call ToLocalTime()
method on it and it shows 11-11-1989 18:00:00 +05:30. (I am in India :p)
我正在寻找类似的东西:
variable1.ToOffset(< timespan>)
I am looking for something like this:
variable1.ToOffset(<timespan>)
如果我给此函数3小时的时间,它将返回我1989年11月11日 19:00:00 +06:30 。
If I give this function a timespan
of 3 hours, It should return me 11-11-1989 19:00:00 +06:30.
我试图更改偏移量,但是offset属性为-只要。有人知道这个有什么解决方法吗?
I tried to change the offset, but offset property is read-only. Does anyone know any workaround for this ?
推荐答案
这很愚蠢。但是,有 是一个名为 ToOffset
的函数,它需要 timespan
作为输入参数!
This is stupid. But there is a function named ToOffset
and it takes timespan
as input parameter!
这篇关于更改datetimeoffset的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!