如何计算时间 [英] How to calculate time

查看:74
本文介绍了如何计算时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



在我的申请表中,我必须生成一份销售报告。



表单将有2个以下的东西



开始时间 - ComboBox(例如上午10:00)

时间跨度 - ComboBox(例如20)



开始时间就像是特定商店那天从上午10:00开始

和跨度是他们计算那天20小时从上午10点开始。



所以我必须从上午10:00到20小时生成销售报告



例如,如果用户选择日期为18-01-2014

开始时间上午10:00

时间跨度20小时



因此它应该从18-01-2014上午10:00到19-01-2014上午6:00给出报告



请提供一些想法如何处理..



谢谢

Hi all

In my application i have to generate a sales report.

In that the form will have below 2 things

Start time - ComboBox(e.g 10:00 am)
time span - ComboBox(e.g 20)

Start time is like for a particular store there day starts at 10:00 am
and span is they calculate there day as 20 hours starting from 10:00 am.

so i have to generate the sales report starting from 10:00 am + 20 hour

e.g if the user select date as 18-01-2014
Start time 10:00 am
Time span 20 hours

so it should give the report from 18-01-2014 10:00 am to 19-01-2014 6:00am

Please need some ideas how to approach..

Thank you

推荐答案

试试这样..



Try like this..

string date = "18-01-2014"; // get from combobox
            string time = "10:00 am"; // get from combobox
            string timespan = "20"; // get from combobox

           double span = Convert.ToDouble(timespan);
           string input = string.Format("{0} {1}",date,time);
          DateTime startTime =  DateTime.ParseExact(input, "dd-MM-yyyy hh:mm tt", null);
          DateTime endTime = startTime.AddHours(span);

          Console.WriteLine(startTime);
          Console.WriteLine(endTime);


这篇关于如何计算时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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