问题描述
我正在使用简单的Bootstrap Datime Picker.
我可以向用户显示的格式是dd MM yyyy. 2016年2月27日
在我的本地计算机上工作正常.
当我将其部署在服务器上时.保存到数据库时,它已开始引发错误.
当我检查时,我发现在srver datime上,如果有时间保存,格式会以某种方式被更改.其2016-02-25.由于我的日期是2015-02-2016,因此会引发错误.
以下是我正在为临时解决方案做的事情.但是我有很多datime控件,并且忙于将它们全部修改并传递给此方法并转换时间,然后保存到db中..
我需要一些全局解决方案
请提出
我尝试过的事情:
公共字符串DateFormating(字符串dateTimeString)
{
字符串inputFormat ="dd/MM/yyyy";
字符串outputFormat ="yyyy/MM/dd";
var dateTime = DateTime.ParseExact(dateTimeString,inputFormat,CultureInfo.InvariantCulture);
字符串输出= dateTime.ToString(outputFormat);
返回输出;
}
Hi ,
I am using simple bootstrap datime picker .
My format to show the user is dd MM yyyy . 27-02-2016
it was working fine on my local .
When i deployed it on server . while saving into database it has started throwing error.
when i checked , i found that on srver datime format is somehow gets chnaged when there is time to save. its 2016-02-25. which throws an error as my date is 2015-02-2016.
below is what I am doing for temp solution . but there are many datime controls i have and its very hectic to chnage them all and pass to this method and convert the time and then save into db ..
I need some global solution
Please suggest
What I have tried:
public string DateFormating(string dateTimeString)
{
string inputFormat = "dd/MM/yyyy";
string outputFormat = "yyyy/MM/dd";
var dateTime = DateTime.ParseExact(dateTimeString, inputFormat, CultureInfo.InvariantCulture);
string output = dateTime.ToString(outputFormat);
return output;
}
推荐答案
DateTime outPutDate = DateTime.ParseExact(yourDate, "dd-mm-yyyy", CultureInfo.CurrentCulture);
这篇关于在我的服务器上保存到sql server时,datetime保存有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!