zoukankan      html  css  js  c++  java
  • c# 时间格式处理,获取格式: 2014-04-12T12:30:30+08:00

    C#  时间格式处理,获取格式: 2014-04-12T12:30:30+08:00

    一.获取格式: 2014-04-12T12:30:30+08:00

    方案一:(局限性,当不是当前时间时不能使用)

          string time = System.DateTime.Now.ToString("s");   //    2014-04-12T12:30:30

                string timeZone = DateTime.Now.ToString("o");     //2014-04-12T12:30:30:19.1562500+08:00

                timeZone = timeZone.Split('+')[1];//08:00

                string str = time + "+" + timeZone;

                Console.WriteLine(str);

    方案二:

         string time = System.DateTime.Now.ToString("s");   //    2014-04-12T12:30:30

         string timeZone=TimeZoneInfo.Local.BaseUtcOffset.ToString(); //08:00

         string str = time + "+" + timeZone;

                 Console.WriteLine(str);

                                                                有更好处理方案的可以回复,分享技术,共同成长。

  • 相关阅读:
    象棋人工智能的实现
    cocos2dx实现象棋之运动
    python基础实战之猜年龄游戏
    python流程控制if判断与循环(for、while)
    python基本算术运算符
    python格式化输出的三种方式
    python解压缩
    python集合
    python元组
    python布尔类型
  • 原文地址:https://www.cnblogs.com/zlp520/p/4990595.html
Copyright © 2011-2022 走看看