zoukankan      html  css  js  c++  java
  • 本地时间与格林威治时间相互转换

    public static DateTime LocalTime2GreenwishTime(DateTime lacalTime)
            {
                TimeZone localTimeZone = System.TimeZone.CurrentTimeZone;
                TimeSpan timeSpan = localTimeZone.GetUtcOffset(lacalTime);
                DateTime greenwishTime = lacalTime - timeSpan;
                return greenwishTime;
            }

    public static DateTime GreenwishTime2LocalTime(DateTime greenwishTime)
            {
                TimeZone localTimeZone = System.TimeZone.CurrentTimeZone;
                TimeSpan timeSpan = localTimeZone.GetUtcOffset(greenwishTime);
                DateTime lacalTime = greenwishTime + timeSpan;
                return lacalTime;
            }

    PS:关于非DateTime类型的字符串格式的转换

    string strDate ="Mon Aug 15 2011 00:00:00 GMT+0800";

    DateTime date = DateTime.ParseExact(strDate, @"ddd MMM dd yyyy HH:mm:ss GMT+ffff", CultureInfo.CreateSpecificCulture("en-US"));

    Response.Write(date.ToString());

     

    string str="Tue Jun 11 09:30:00 UTC 0800 2013";

    DateTime dt=DateTime.ParseExact(str,"ddd MMM dd HH:mm:ss 'UTC' 0800 yyyy", System.Globalization.CultureInfo.InvariantCulture);

    Response.Write(date.ToString());

  • 相关阅读:
    代码艺术 CountDownTimer
    java 正则
    What are the top 10 things that we should be informed about in life
    java 闭包与回调
    Hive记录-单机impala配置
    Hbase记录-Hbase介绍
    Hbase记录-Hbase其他工具
    Hbase记录-Hbase shell使用命令
    Hbase记录-Hbase Web管理工具
    CM记录-Hadoop运维管理
  • 原文地址:https://www.cnblogs.com/hlxt548826/p/3945464.html
Copyright © 2011-2022 走看看