首页 \ 问答 \ 从服务器获取当前日期时间并将其转换为c#中的本地时间(Get current date time from server and convert it into local time in c#)

从服务器获取当前日期时间并将其转换为c#中的本地时间(Get current date time from server and convert it into local time in c#)

帮助:我有一台服务器,有时间在格林威治标准时间-07.00小时。 我当地时间是格林威治标准时间+05.30。 我需要从服务器获取当前日期和时间,并将此日期和时间转换为我当地时间。 我尝试了很多代码,但仍未找到连续的方法。 有人可以帮帮我。

string zoneId = "India Standard Time";
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
DateTime result = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi);
DateTime cu = result.ToUniversalTime();
DateTime cur = cu.ToLocalTime();

我已经尝试了上述所有方法,但仍然没有得到正确的答案。 假设我当前的当地时间是2014年3月9日下午12:51:00,那么我的服务器时间将是12.30小时,与当地时间不同,即从当地时间减去12小时30分钟以获得服务器时间。 我需要从服务器时间获取当地时间。 它怎么能实现? 请建议我一些解决方案..提前感谢您的答案


Help: I have a server which is having time in GMT-07.00 hours. My local time is GMT+05.30 hours. I need to get current date and time from server and convert this date and time into my local time. I have tried many codes, but still have not found a successive way of doing this. Can somebody please help me out.

string zoneId = "India Standard Time";
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
DateTime result = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi);
DateTime cu = result.ToUniversalTime();
DateTime cur = cu.ToLocalTime();

I have tried all the above methods, still I'm not getting the correct answer. Suppose my current local time is 09-Mar-2014 12:51:00 PM, then my server time would be 12.30 hours different from my local time, ie subtract 12 hours and 30 minutes from my local time to get my server time. I need to get my local time from the server time. How can it be acheived?? Please suggest me some solutions.. Thanks in advance for your answers


原文:https://stackoverflow.com/questions/22279525
更新时间:2023-11-26 14:11

最满意答案

您可以使用对omp_get_max_threads()的调用。


You could use a call to omp_get_max_threads().

相关问答

更多
  • 您可以使用对omp_get_max_threads()的调用。 You could use a call to omp_get_max_threads().
  • 我不确定这里发生了什么。 可能是您使用存根OpenMP库编译的情况,该存根OpenMP库提供所有OpenMP库API,但仅表现为顺序模式(例如,对于相应的英特尔编译器开关,请参阅此链接 )。 另一种可能性是在您的环境中将OMP_THREAD_LIMIT环境变量设置为1 。 请参阅此代码: #include #include int main() { omp_set_num_threads(8); #pragma omp parallel #pr ...
  • 我最初的反应是:你必须声明更多的并行性。 您已定义了两个可以并行运行的任务。 OpenMP在两个以上内核上运行它的任何尝试都会降低您的速度(因为缓存局部性和可能的错误共享)。 编辑如果并行for循环具有任何重要的卷(例如,不超过8次迭代),并且您没有看到使用超过2个核心,请查看 omp_set_nested() OMP_NESTED = TRUE | FALSE环境变量 此环境变量启用或禁用嵌套并行性。 可以通过调用omp_set_nested()运行时库函数来覆盖此环境变量的设置。 如果禁用嵌套并行性,则 ...
  • 关于您的第一个问题:您的功能有效性是在并行循环中实现低于串行性能的完美方式。 但是,您已经给出了正确的答案。 您应该为每个线程填充独立的向量,然后将它们合并。 inline void CNetwork::Validity() { #pragma omp parallel for for ( uint32_t i = 0 ; i < num_elements ; i++ ) { #pragma omp critical remove_node_v.push_back(i); } } 编辑: ...
  • #pragma omp critical具有序列化循环的效果,因此摆脱它应该是你的第一个目标。 这应该是朝着正确方向迈出的一步: ptrdiff_t const c = count(dat[0].begin(), dat[0].end(), delm) + 1; vector > dist(dat.size(), vector(dat.size())); #pragma omp parallel for for (size_t p = 0; p != dat. ...
  • 如果一个线程阻塞,操作系统的调度程序应该自动切换到另一个可运行的线程(如果有的话),所以你不需要做任何事情。 但是,如果您的所有OpenMP程序都在调用CUDA内核,那么GPU很可能是瓶颈,因此无论如何都不会从CPU上使用线程中获得太多好处。 根本不值得使用OpenMP。 但是,如果继续使用OpenMP,则应该向该omp parallel for添加collapse(2) 。 If a thread blocks, the operating system's scheduler should automa ...
  • 所以,你知道通过查看存在负载平衡问题的代码,IMO你应该用schedule(static,1)进行测试,以保证你在线程之间有最小的负载平衡(最多只有一次迭代)。 比计划(动态,1)比较并验证使用动态(动态具有内部锁定机制)的开销是否被平衡线程间工作的收益所淹没。 如果你仔细检查内环的工作就像一个三角形(N = SIZE): *k/i 0 1 2 3 4 5 ... N-1 * 0 - x x x x x ... x * 1 - - x x x x ... x * 2 - - - x x x ...
  • 按照Ben和Rick的建议,我在没有omp pragma(连续)的情况下测试了以下循环,并获得了我预期的结果(非常慢)。 重新添加pragma之后,并行代码也会按预期执行。 看起来问题在于将索引声明为循环外部的私有,或者在循环内将numTargets声明为私有。 或两者。 int numTargets = targetList.size(); #pragma omp parallel for for (int index = 0; index < numTargets; ++inde ...
  • 在很多情况下,场景2不会给线性加速 - 线程之间的虚假共享(或者就此而言,共享变量的真实共享得到修改),内存带宽争用等。子线性加速通常真实的,不是测量神器。 更一般地说,一旦你将定时器放入循环中,你就会考虑更细粒度的定时信息,而不是真正适合用这种定时器进行测量。 您可能希望能够将线程管理开销与实际正在进行的工作omp_get_wtime() ,原因有很多,但在此尝试通过向omp_get_wtime()插入N个额外的函数调用以及算术还原操作,所有这些操作都会产生不可忽视的开销。 如果你真的想要准确comput ...
  • totalThreads在您的OpenMP版本中来自哪里? 我打赌它不是startIndex.size() 。 OpenMP版本将请求排队到totalThreads工作线程。 看起来C ++ 11版本创建了startIndex.size()线程,如果这是一个很大的数字,它会涉及大量的开销。 Consider the following code. The OpenMP version runs in 0 seconds while the C++11 version runs in 50 seconds. ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)