在c#语言中的时间处理有几种方式:

首先获取当前时间:var date=new DateTime.Now;

date.ToString()----2111-1-20 11:44:47

date.ToShortDateString()---2111/1/20

date.ToShortTimeString()--- 11:47

date.ToString("yyyy-MM-dd hh:mm:ss");//2004-08-12 04:42:34

date.ToString("yyyy-MM-dd");//2004-08-12

date.ToString("HH:mm:ss");//16:42:41

ToShortTimeString()是取得时间中的小时和分钟,ToString()是获取整个时间包括年月日 小时分钟 秒。

ToShortDateString 方法所返回的字符串区分区域性。它反映当前区域性的 DateTimeFormatInfo 对象所定义的模式。例如,对于 en-US 区域性,标准短日期模式为“M/d/yyyy”;对于 de-DE 区域性,该模式为“dd.MM.yyyy”;对于 ja-JP 区域性,该模式为“yyyy/M/d”。此外,也可以在特定计算机上自定义特定格式字符串,以便该字符串不同于标准短日期格式字符串。

日期用ToShortDateString格式化,为什么换了机器以后得出来的不是xxxx-xx-x的形式,而是x/xx/xxxx?

只要在控制面板中的"区域和语言选项"设置"区域选项"就行了

ps:尝试转化时间,防止报错

DateTime dtcreate;
string strDate = string.Empty;
if (DateTime.TryParse(dt.Rows[i]["CreateDate"].ToString(), out dtcreate))
{
        strDate = dtcreate.ToShortDateString();
 }

C#时间格式 tostring、toshortdatestring、toshorttimestring的更多相关文章

  1. ToString()的各种用法(大全) C# 获取所有国家时间格式

    ToString()的各种用法(大全)   常用例子: string str = ""; str = 123456.ToString("N"); //生成 12 ...

  2. donet core 2.1 DateTime ToString() 方法 在不同平台返回的时间格式不一样?

    跟操作系统的 设置的时间格式和系统区域设置有关.为了保持一致性.参数自己写好格式.

  3. asp.net C# 时间格式大全

    asp.net C# 时间格式大全DateTime dt = DateTime.Now;//   Label1.Text = dt.ToString();//2005-11-5 13:21:25//  ...

  4. C# 时间格式总结

    C#时间/日期格式大全 C#时间/日期格式大全,C#时间/日期函数大全 有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06- ...

  5. C#时间格式之GMT时间的格式

    GMT:格林尼标准时间  北京时间=GMT时间+8小时 DataTime nowDate = DataTime.Now; nowDate.toString("r");    效果为 ...

  6. JavaScriptSerializer 序列化json 时间格式

    利用JavaScriptSerializer 序列化json 时间格式,得到的DateTime值值显示为“/Date(700000+0500)/”形式的JSON字符串,显然要进行转换 1.利用字符串直 ...

  7. Newtonsoft.Json 序列化和反序列化 时间格式

    From : http://www.cnblogs.com/litian/p/3870975.html 1.JSON序列化 string JsonStr= JsonConvert.SerializeO ...

  8. JAVA时间格式转换大全

    import java.text.*; import java.util.Calendar; public class VeDate { /** * 获取现在时间 * * @return 返回时间类型 ...

  9. JS时间格式 GMT格式转换

    JavaScript时间格式转换总结 1.当前系统区域设置格式(toLocaleDateString和toLocaleTimeString) 例子:(new Date()).toLocaleDateS ...

随机推荐

  1. 如何从iTunes Connect中提款呢?

    最近在AppStore有点小小小收入,但如何从iTunes Connect中提款呢? (Payments and Financial Reports) 网上查了下,发现有种说法:“只要账号余额达到15 ...

  2. MySql5.5忘记root密码的解决方法

    试了很多方法,下面这种方法是确保可以成功的,呵呵.转载自:http://hi.baidu.com/bjben/item/722bb50b27baf1dcdde5b097. 申明:本文章应该属于转载,但 ...

  3. PHP apache2.2 mysql 的安装

    1.安装准备 我的系统为win7 旗舰版 php:http://windows.php.net/downloads/releases/php-5.3.6-Win32-VC9-x86.zip mysql ...

  4. SQL Server 2008数据库重命名方法

    假设SQL Server 2008中有个数据库test,现在要将其改名为zhy步骤:(1) 分离数据库:打开management studio,找到test数据库-->右键-->任务--& ...

  5. dwr2反推

    package services; import org.directwebremoting.Browser; import org.directwebremoting.ScriptSessions; ...

  6. java追加文件的几种方式

    import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.FileWriter; import ja ...

  7. 过滤文本文档中的数据并插入Cassandra数据库

    代码如下: package com.locationdataprocess; import java.io.BufferedReader; import java.io.File; import ja ...

  8. java中无符号类型的处理

    在Java中,不存在Unsigned无符号数据类型,但可以轻而易举的完成Unsigned转换. 方案一:如果在Java中进行流(Stream)数据处理,可以用DataInputStream类对Stre ...

  9. C++中String类的实现

    原文:http://noalgo.info/382.html String是C++中的重要类型,程序员在C++面试中经常会遇到关于String的细节问题,甚至要求当场实现这个类.只是由于时间关系,可能 ...

  10. 标准库 - fmt/format.go 解读

    // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a B ...