字符串转换为DATETIME格式DD-MMM-YYYY问题 [英] Convert string to Datetime format dd-MMM-yyyy issue
本文介绍了字符串转换为DATETIME格式DD-MMM-YYYY问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从数据库中的字符串变量的员工的帐户到期日并在此字符串变量的值的格式为:2016年6月26日上午09点14分03秒。现在我想这种格式在DD-MMM-YYYY HH转换:MM:SS AM / pm.How我可以解决这个
。我尝试以下code:
的DateTime passexpiredate = DateTime.ParseExact(app_user.GetPasswordExpiry(EMP code),DD-MMM-YYY HH:MM TT,NULL);
lblPassExpiry.InnerText =密码到期日期:+ passexpiredate.ToString();
解决方案
您已经通过在所需的日期时间格式的ToString()
方法如下所述:
的DateTime passexpiredate = DateTime.Parse(app_user.GetPasswordExpiry(EMP code));
lblPassExpiry.InnerText =密码到期日期:+ passexpiredate.ToString(DD-MMM-YYY HH:MM TT);
I am getting the account expiry date of the employee from database in a string variable and the values which is in this string variable is in the format : 6/26/2016 9:14:03 AM. Now i want this format to be converted in dd-mmm-yyyy hh:mm:ss am/pm.How can i resolve this.
I tried the following code :
DateTime passexpiredate = DateTime.ParseExact(app_user.GetPasswordExpiry(empCode), "dd-MMM-yyy hh:mm tt", null);
lblPassExpiry.InnerText = "Password Expiry Date: "+passexpiredate.ToString();
解决方案
You've to pass the required date time format in ToString()
method as mentioned below:
DateTime passexpiredate = DateTime.Parse(app_user.GetPasswordExpiry(empCode));
lblPassExpiry.InnerText = "Password Expiry Date: " + passexpiredate.ToString("dd-MMM-yyy hh:mm tt");
这篇关于字符串转换为DATETIME格式DD-MMM-YYYY问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文