c# - How to log the real user time? -


i logging users login app , times. see time based on app server case azure, it's not real time. interested show real times login. seems app server default, how make time more legitimate?

var loginaudit = new loginaudit(); loginaudit.client_ip = fdb.utils.getclientip(); loginaudit.login_time = datetime.now; loginaudit.login_user_id = objuser.loginid; loginaudit.logout_time = null; loginaudit.type = "in"; loginaudit.user_id = objuser.userid;  db.entry(loginaudit).state = system.data.entity.entitystate.added; db.savechanges(); 

showing dates relative clients particular timezone considered display problem, whenever dealing storing dates/times it's recommended record them utc. @ moment, recording servers local time against audit record means absolutely nothing regards clients.

what want record current utc time in db record

loginaudit.login_time = datetime.utcnow; 

then when displaying, convert local time.

in order need culture aware, in other words, need know timezone client on in order translate utc local. example, if client, working in gmt standard time time, in order me see audit time relative me need do

var gmt = timezoneinfo.findsystemtimezonebyid("gmt standard time"); var localtime = tzi.converttimefromutc(loginaudit.login_time, gmt); 

in terms of how information client, there various ways of doing letting user select list of available tz (reliable intrusive) using 3rd party service lookup information based on ip (not reliable better ux user) - i'll leave investigate , decide best app.

alternatively, if prefer not deal timezones , work dates store offset along utc time give local time once calculated - see datetimeoffset.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -