简体   繁体   中英

Date time changed in date = date

This is my code

model.dateOfBirth is date time from datepicker but it is date not string

In addition current culture is fa-IR

dateOfBirth = model.dateOfBirth.Value;
//model.dateOfBirth.Value = {13/05/1367 12:00:00 ق.ظ} tick = 627222528000000000
//dateOfBirth = {04/08/1988 12:00:00 ق.ظ} (it is true in text but not in value) tick!!! = 823262400000000000

question updated

Why thay are not equal?

model.dateOfBirth.Value.Tick != dateOfBirth.Value.Tick

627222528000000000 = 1988-08-04​T00:00:00.000Z

823262400000000000 = 2609-10-26​T00:00:00.000Z

The question is why date is changed by = expertion ?

I can fix the problem but the question is why value changed?

I fixed this by:

 dateOfBirth = new DateTime(model.dateOfBirth.Value.Ticks);

I found the problem maybe in Culture (current thread culture is fa-IR ) or .net bug for avoid future problem I used Tick value instead of = and create new date by Tick value of model.dateOfBirth.Value.Ticks therefore my new dateOfBirth time value have exact tick value as model.dateOfBirth.Value.Ticks and now are same date value.

Code:

dateOfBirth = new DateTime(model.dateOfBirth.Value.Ticks);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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