c# - Same code but getting different result -
when use below code getting different result on developer pc , remote server.
string _qsdatetime = "12.11.2016 21:30"; var _countryzone = datetimezoneproviders.tzdb["tur"]; var _datepattern = localdatetimepattern.createwithcurrentculture("yyyy-mm-dd hh:mm:ss"); var _localtime = _datepattern.parse(_qsdatetime).value; var _localtime2targetzonetime = _localtime.inzonestrictly(_countryzone); var _targetzone2utc = _localtime2targetzonetime.withzone(datetimezone.utc).todatetimeutc(); _qsdatetime = _targetzone2utc.tostring("yyyy-mm-dd hh:mm:ss"); developer pc result is: "2016-11-12 19:30:00" remote server result is: "2016-12-11 19:30:00"
remote server specs windows 2012 server english developer pc specs windows 7 turkish both of them regional date time setting same.
why getting different result?
i'm not too much familiar noda time have few things say:
datetimezoneproviders.tzdbnot have time zone identifierturfar know, should useeurope/istanbulinstead.- when create
localdatetimepatterncreatewithcurrentculturemethod, uses current culture settings , these different in both server. careful that. localdatetimepattern.parsemethod use rules of current pattern. string12.11.2016 21:30patternyyyy-mm-dd hh:mm:ss. see point, don't you?- if different results in servers, shouldn't blame last line since both
en-us,tr-trcultures usesgregoriancalendarcalendarproperty , doesn't effect result. might wanna checklocaldatetimepattern.parsemethod line instead.
for example;
using system; using nodatime; using nodatime.text; public class program { public static void main() { string _qsdatetime = "12.11.2016 21:30"; var _countryzone = datetimezoneproviders.tzdb["europe/istanbul"]; var _datepattern = localdatetimepattern.createwithcurrentculture("dd.mm.yyyy hh:mm"); var _localtime = _datepattern.parse(_qsdatetime).value; var _localtime2targetzonetime = _localtime.inzonestrictly(_countryzone); var _targetzone2utc = _localtime2targetzonetime.withzone(datetimezone.utc).todatetimeutc(); _qsdatetime = _targetzone2utc.tostring("yyyy-mm-dd hh:mm:ss"); console.writeline(_qsdatetime); } } generates
2016-11-12 19:30:00 here demonstration.
Comments
Post a Comment