UTC Time related issue in Application, (C#,ASP.NET & SQL)

眉间皱痕 提交于 2019-12-02 15:52:47

问题


I am developing one application related to Sales & Purchase reports. In that I am generating chart by using the data of that purchase & sales report.

The creation of purchase order & sales order date is with respect to the (UTC + 5.30) time i.e. this time is for Mumbai,India.

Scenario -1

Suppose this is the scenario (currently This application is used in India For This scenario)

Lets Say, 
**Purchase Order & sales Order Generation is as follows**
                      Purchase Order(Rs)       Sales Order(Rs)
    31-Jan-2014 11.00PM      1000                   2000  
    31-Jan-2014 10.00PM      2000                   4000

According to this if I create chart then data for the chart will look like this.

              Purchase   Sales
 Jan-2014       3000     6000

I don't have any issue with this scenario,

But Lets Suppose I have one branch in US & one of my US colleague created Same purchase order & sales order then My problem is starts as follows

Scenario -2

Suppose this is the scenario (currently This application is used in US For This scenario)

Lets Say, 
    **Purchase Order & sales Order Generation is as follows**
                     Purchase Order(Rs)  Sales Order(Rs)
31-Jan-2014 11.30PM      1000                   2000  
31-Jan-2014 11.00PM      2000                   4000

According to this If I create a chart then data for the chart will look like this.

              Purchase   Sales
 Feb-2014       3000     6000

Reason for This : Because I am using (UTC+5.30) time to create Purchase & sales Report. For the guy who is sitting in the US & creating the purchase order on the date of 31-Jan-2014 12.00PM
(Timing for US is UTC)

So According to US, Sales & purchase Order Date is 31-Jan
So According to India, Sales & purchase Order Date is 1-Feb

Question : Then What is the Standard way to solve this and what should I display in the chart or in the whole application, with the US or with the Indian time or some common time Because end user who is using this application that person will not know what is UTc that person will only interested in the correct values.

Thank you. Any help will be appreciated.


回答1:


To handle these situations we should always use the date time in UTC format in code DateTime.UtcNow and in database GETUTCDATE().

Please refer the link below:

how to handle time zones and dates in multi country/lingual application

http://msdn.microsoft.com/en-us/library/bb397769.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-3



来源:https://stackoverflow.com/questions/25988685/utc-time-related-issue-in-application-c-asp-net-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!