查找系统时间与其他国家/地区时间之间的时差 [英] To find difference between System time and other country time

查看:94
本文介绍了查找系统时间与其他国家/地区时间之间的时差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们想找出C#中两个日期之间的差异.我想计算美国时机和印度时机之间的差异.

Hi friends want to find the difference between two dates in C#. I wanted to calculate the difference between U.S timing and Indian timing.

DateTime dat1 = DateTime.Now;
            DateTime dat2 = DateTime.Now.AddMinutes(-150);
            TimeSpan diff = dat2 - dat1;
            
            int hour = diff.Hours;
            int min = diff.Minutes;
            int secs = diff.Seconds;

            string timedif = hour.ToString("00") + ":" + min.ToString("00") + ":" + secs.ToString("00");

            if (isr.Checked == true)
            {
                label3.Text = timedif;
            }


当我编写上面的代码时,我没有得到正确的答案.


When i write the above code i am not getting the proper answer..

推荐答案

您的第一个问题是没有美国时间"这样的东西.美国有多个时区,因此您首先需要确定要使用哪个时区.您使用了150分钟(两个半小时)的偏移值,这仅使您从印度时间(UTC加5:30)到沙特阿拉伯(UTC + 3:00).您还将打印时差的值,该值将是2小时30分钟.
Your first problem is that there is no such thing as "US time". The US has multiple time zones so you first need to decide which one to use. You have used an offset value of 150 minutes (two and a half hours) which only takes you from India time (UTC plus 5:30) to Saudi Arabia (UTC + 3:00). You are also printing the values of the time difference which will be 2 hours and 30 minutes.


这篇关于查找系统时间与其他国家/地区时间之间的时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆