欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#實(shí)現(xiàn)日期格式轉(zhuǎn)換的公共方法類實(shí)例

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例講述了C#實(shí)現(xiàn)日期格式轉(zhuǎn)換的公共方法類。分享給大家供大家參考,具體如下:

這里演示了C#中一些日期格式的轉(zhuǎn)換。

創(chuàng)建公共方法類(UtilityHandle.cs),代碼如下:

/// <summary>
/// 公共方法類
/// </summary>
public static class UtilityHandle
{
  /// <summary>
  /// 字符串日期轉(zhuǎn)DateTime
  /// </summary>
  public static DateTime TransStrToDateTime(string strDateTime)
  {
    DateTime now;
    string[] format = new string[]
    {
      "yyyyMMddHHmmss", "yyyy-MM-dd HH:mm:ss", "yyyy年MM月dd日 HH時(shí)mm分ss秒",
      "yyyyMdHHmmss","yyyy年M月d日 H時(shí)mm分ss秒", "yyyy.M.d H:mm:ss", "yyyy.MM.dd HH:mm:ss","yyyy-MM-dd","yyyyMMdd"
      ,"yyyy/MM/dd","yyyy/M/d"
    };
    if (DateTime.TryParseExact(strDateTime, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out now))
    {
      return now;
    }
    return DateTime.MinValue;
  }
  /// <summary>
  /// 日期轉(zhuǎn)換
  /// </summary>
  public static string TransformDataLong(DateTime? dateTime)
  {
    string result = "";
    if (dateTime.HasValue)
    {
      result = dateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
    }
    return result;
  }
  /// <summary>
  /// 日期轉(zhuǎn)換
  /// </summary>
  public static string TransformDataShort(DateTime? dateTime)
  {
    string result = "";
    if (dateTime.HasValue)
    {
      result = dateTime.Value.ToString("yyyy-MM-dd");
    }
    return result;
  }
  /// <summary>
  /// 將日期轉(zhuǎn)換成decimal
  /// </summary>
  public static decimal TransDateTimeToDecimal(DateTime date)
  {
    decimal ret = 0;
    ret = Convert.ToDecimal(date.ToString("yyyyMMddHHmmss"));
    return ret;
  }
  /// <summary>
  /// 將decimal轉(zhuǎn)換成日期格式
  /// </summary>
  /// <param name="date">yyyyMMddHHmmss</param>
  /// <returns>yyyy-MM-dd HH:mm:ss</returns>
  public static string TransDecimalToDateTime(string date)
  {
    DateTimeFormatInfo dtfi = new CultureInfo("zh-CN", false).DateTimeFormat;
    DateTime dateTime = DateTime.Now;
    DateTime.TryParseExact(date, "yyyyMMddHHmmss", dtfi, DateTimeStyles.None, out dateTime);
    return dateTime.ToString("yyyy-MM-dd HH:mm:ss"); ;
  }
}

PS:這里再為大家推薦幾款日期與時(shí)間相關(guān)工具供大家參考使用:

在日期天數(shù)差計(jì)算器:
http://tools.jb51.net/jisuanqi/onlinedatejsq

在線日期計(jì)算器/相差天數(shù)計(jì)算器:
http://tools.jb51.net/jisuanqi/datecalc

在線日期/天數(shù)計(jì)算器:
http://tools.jb51.net/jisuanqi/date_jisuanqi

在線陰歷/陽歷轉(zhuǎn)換工具:
http://tools.jb51.net/bianmin/yinli2yangli

在線天數(shù)計(jì)算器(flash版):
http://tools.jb51.net/jisuanqi/datejsq

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#字符串操作技巧總結(jié)》、《C#數(shù)組操作技巧總結(jié)》、《C#中XML文件操作技巧匯總》、《C#常見控件用法教程》、《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》、《C#操作Excel技巧總結(jié)》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》及《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

上一篇:C#中WinForm控件的拖動(dòng)和縮放的實(shí)現(xiàn)代碼

欄    目:C#教程

下一篇:使用C#給PDF文檔添加注釋的實(shí)現(xiàn)代碼

本文標(biāo)題:C#實(shí)現(xiàn)日期格式轉(zhuǎn)換的公共方法類實(shí)例

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5958.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有