在一个变量中将小时数增加至分钟数 [英] adding hours to minutes in one variable

查看:78
本文介绍了在一个变量中将小时数增加至分钟数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有一个变量,它在另一个变量"45"中保存小时数,例如"3",其分钟数,我需要使一个新变量完整地保存时间,而不包含日期,该日期包含小时+分钟数"03:45",

任何需要帮助的人
谢谢

hi all
i have variable holds numbers of hours like "3" and its minutes in another variable "45" , i need to make anew variable holds time as a whole without date which contains hour + its minutes "03:45" ,

any help pleaseeeeee
thanks

推荐答案

使用 TimeSpan 结构.

int小时= 3,分钟= 45,秒= 0;
Use a TimeSpan structure.

int hours = 3, minutes = 45, seconds = 0;
TimeSpan myTime = new TimeSpan(hours, minutes, seconds);


那么,这段代码呢:
So, what about this code:
int nHours = 3;
int nMinutes = 45;
int nTotalMinutes = nHours * 60 + nMinutes;

MessageBox.Show("Time: " + (nTotalMinutes / 60).ToString() + ":" + (nTotalMinutes % 60).ToString()); //Time: 3:45


这篇关于在一个变量中将小时数增加至分钟数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆