am,pm时间转换
写在前⾯
最近遇到的⼀个问题,在英⽂操作系统上,获取到的时间是带am或者pm的。但是数据库是datetime类型,存储的时候竟然都变成
0000-00-0000:00:00.但是在中⽂操作系统上⼜是正常的。没办法只有转换了。
解决⽅案
其实很多时候Time()这个⽅法完全满⾜需求。可有些地⽅确实⽐较蛋疼,这⾥还是记录⼀下,加深印象。
⽅式⼀
classProgram
{
staticvoidMain(string[]args)
{
//Summary:
//eInfoclass
//badontheculturespecifiedbynameandontheBooleanthatspecifies
//whethertoutheur-lectedculturettingsfromthesystem.
//
//Parameters:
//name:
//eInfoname,
//eInfo,orWindows-onlyculture
//notca-nsitive.
//
//uUrOverride:
//ABooleanthatdenoteswhethertoutheur-lectedculturettings
//(true)orthedefaultculturettings(fal).
meFormatInfodtInfo=eInfo("en-Us",true).DateTimeFormat;
//Getsortsthecustomformatstringforashorttimevalue.
imePattern="t";
DateTimedt=("05-28-1503:07PM",dtInfo);
ine(dt);
();
}
输出
⽅式⼆
stringstrDt="2014-03-0203:07PM";
strDt=("PM".ToCharArray());
DateTimedt=Time(strDt).AddHours(12);
ine(dt);
总结
这也是在开发中遇到的⼀个问题,觉得好奇,就查看了下实现⽅式,遇到了,就记录下吧。
本文发布于:2022-11-16 00:47:35,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/88/27748.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |