且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将对象转换为日期时间.

更新时间:2023-02-14 12:07:13

做到这一点的方法是

The way to do it would be

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[^]


如果内部接收到的对象的数据类型为datetime,则将通过显式分配将其转换为Datetime.

看起来,在内部它不是日期时间类型.您需要对其进行显式转换.
此处:
If the object recieved was of datatype datetime internally then it will be converted into Datetime by explicit assignment.

Looks like, internally it is not of datetime type. You need to convert it explicitly.
Here:
Object exist = events.getStartDateOfEvent(EventID, OrganizerID);
DateTime dt1 = Convert.ToDateTime(exist);