编写一个程序,利用求余运算完成24小时制与12小时制之间的转换!
还请各位大哥帮忙,谢谢!~~
------解决方案--------------------
思路是除十二余零。
public class Samples {
public static void Main() {
DateTime MyDateTime = DateTime.Now;
rtntime(MyDateTime);
}
public datetime rtntime(datetime datenow ) {
DateTime rtn;
int hour=datenow.Hour;
int mv;
mv = Mod(hour,12);
if (mv=0)
mv=12;
rtn=new System.DateTime(datenow.Year, datenow.Month, datenow.Day, mv, datenow.Minute, datenow.Second, datenow.Millisecond);
return rtn;
}
}
自己再改改吧。