问题描述
将对象转换为DateTime时遇到问题.我遇到以下问题:
getStartDateOfEvent是我的存储过程.
业务逻辑:
对象存在= events.getStartDateOfEvent(EventID,OrganizerID);
DateTime dt1 =(DateTime)存在;
我在进行调试时得到的值是:7/9/2012 12:34:45 PM
并在dt1中获得值1/1/0001 12:00:00 AM
那么确切的解决方案是什么.我已经尝试了很多方法,但没有得到任何解决方案.
Hi,
I am getting an issue while converting an object into DateTime. I am getting the following problem :
The getStartDateOfEvent is my stored procedure.
Business Logic :
Object exist = events.getStartDateOfEvent(EventID, OrganizerID);
DateTime dt1 = (DateTime)exist;
The value i get while debugging in exist is : 7/9/2012 12:34:45 PM
and in dt1 i get the value 1/1/0001 12:00:00 AM
So what will be the exact solution. I have tried in many ways but not getting any solution.
推荐答案
string MyString = exist.tostring();
DateTime dt1 = DateTime.ParseExact(MyString, "yyyy-MM-dd HH:mm tt",
null);
您可能还会发现此有用
轻松将字符串转换为DateTime,将DateTime转换为字符串和格式 [ ^ ]
you may also find this useful
Easy String to DateTime, DateTime to String and Formatting[^]
Object exist = events.getStartDateOfEvent(EventID, OrganizerID);
DateTime dt1 = Convert.ToDateTime(exist);
这篇关于如何将对象转换为日期时间.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!