Closed Huanqiang closed 8 years ago
我怀疑是不是时区的问题呢?但是我不知道怎么改,还请麻烦您看下。
I don't understand Chinese. Would you tell me your issue in English?
@naoty Sorry: my English is not good. I am trying to set the start time of today (for example: 2016-01-29 00:00:00), but the result is not right. Code as follows:
I suspect that this problem is related to the time zone? But I do not know how to change, but also please trouble you.
Hi,sir: I'm so sorry to bother you, but I really don't know how to solve this problem. Please, help me.
There is something wrong... I'll try to investigate this problem! Thank you for reporting.
Thank you for your efforts, look forward to your results, thank you
@861645007 Sorry for late reply! I found that the result of print(date)
looks strange, but actually todayEnd.hour
returns 0
. Screenshots are here.
This problem is caused by the wrong implementation of CustomStringConvertible
for extended NSDate
. This protocol defines a customized text format returned by print
and so on.
I will try to fix the implementation! Thank you for reporting!
It seems that the override of description
, which is defined at CustomStringConvertible
, is not allowed. I don't know how to solve this problem...
I think that the problem is UTC and GMT。we can get UTC of time from NSDate()
, but current time which we print is GMT, It is a difference of 8 hours(when i use beijing time)
I don't know if my guess is right, please look at it.
Yes, your guess is right. The result of print
ignores the timezone because the implementation of CustomStringConvertible
for extended NSDate
doesn't consider the timezone. If possible, I want to override describe
property to consider the timezone. But, it seems that the override is not allowed...
hi: I think you can use this method to change the time. Although this is not a good way, it can be a temporary solution to this problem. i hope you can find a better method.
func tolocalTime() -> NSDate { let tz = NSTimeZone.localTimeZone() let seconds: NSInteger = tz.secondsFromGMTForDate(self) return NSDate(timeInterval: Double(seconds), sinceDate: self) }
func tolocalTime() -> NSDate {
let tz = NSTimeZone.localTimeZone()
let seconds: NSInteger = tz.secondsFromGMTForDate(self)
return NSDate(timeInterval: Double(seconds), sinceDate: self)
}
@861645007 If you want to change the timezone, you should use -change(timeZone:)
at here.
BTW, would you change the title of this issue in English?
-change(timeZone:)
this method can't play a part in this problem
@861645007 Could you send a pull request includes tests regenerating your problem and codes solving them?
你好:我在尝试设置今天的开始时间(就是0点0分),但是获取的结果不正确。代码如下