zoukankan      html  css  js  c++  java
  • 日期格式与字符串格式互转

    1、日期格式转换成字符串:

    string timestr=dt.ToShortDateString();
    或 string timestr=dt.ToShortTimeString();
    或 string timestr=dt.ToString("yyyyMMdd");

    说明:自定义格式转换中 yyyy代表年,如2008,yy也代表年,如08年,大写MM代表月,dd代表日,hh代表小时,小写mm代表分钟,ss代表秒数。

    2、字符串格式转换成日期格式的代码:

    DateTime dt=Convert.ToDateTime("2008-06-30");
    里面的字符串格式要固定的,如果不是上面所写的形式,则需要通过字符串处理函数修改字符串!

    补充:
    精确到时分秒的写法
    DateTime dt=Convert.ToDateTime("2008-06-30 11:11:10");
    string timestr=dt.ToString("yyyyMMddhhmmss");//hh:12时制 HH:24时

  • 相关阅读:
    python 学习
    快速排序
    U3D AStar 案例
    U3D AStar 算法原理
    .net core 实时通讯
    .net 算法复杂度
    U3D MVC 背包案例
    U3D 对象池
    Unity网络基础(NetWork)
    U3D Socket实现简易通讯
  • 原文地址:https://www.cnblogs.com/qfcndtt/p/2010257.html
Copyright © 2011-2022 走看看