日期时间Asp.NET [英] DateTime Asp.NET

查看:119
本文介绍了日期时间Asp.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存数据库与ASP.NET的日期。日期在数据库中的数据类型是日期时间
我想把它保存为例子(23/02/2014 00:00:00)

也就是说,我要保存日期,月份和年份,然后有时间永远是00:00:00。我也希望有一个月和/或前一天零点的时候都只有一个号码。例如2014年2月6日,而不是2014年2月6日。

这是可能的,当数据类型是 VARCHAR ,但我会怎么做时,数据类型为日期时间 <? / p>

解决方案

 则DateTime.ToString(DD / MM / YYYY);

将时间设置为零。
MM和DD将根据需要添加零

SQL就知道了正确的日期,如果你补充一点:

<$p$p><$c$c>DateTime.Now.ToString(\"dd/MM/yyyy\",System.Globalization.CultureInfo.GetCultureInfo(\"he-IL\"));

更新

  System.Globalization.CultureInfo信息= CultureInfo.CurrentCulture;
          Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(他-IL);            command.Parameters.AddWithValue(@信息,DateTime.Now);
          Thread.CurrentThread.CurrentCulture =信息;

I'm trying to save a date in database with ASP.NET. The datatype of Date in the database is datetime. I want to save it as for example (23/02/2014 00:00:00)

That is, I want to save Date, Month and Year, and then have time always be 00:00:00. I also want to have zeros before month and/or day when they are only one number. e.g. 02/06/2014 instead of 2/6/2014.

This is possible when the datatype is varchar but how would I do this when the datatype is datetime?

解决方案

dateTime.ToString("dd/MM/yyyy");

will set the time to zero. MM and dd will add zero if needed

SQL will know the correct date if you add this:

DateTime.Now.ToString("dd/MM/yyyy",System.Globalization.CultureInfo.GetCultureInfo("he-IL"));

update

System.Globalization.CultureInfo info = CultureInfo.CurrentCulture;
          Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("he-IL");

            command.Parameters.AddWithValue("@info",DateTime.Now);
          Thread.CurrentThread.CurrentCulture = info;

这篇关于日期时间Asp.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆