Converting DateTime To Currency

  • Thread starter Thread starter Jamsos
  • Start date Start date
J

Jamsos

Guest
Hello, Developer friends,


I hope that you are well.


I have made some progress with my code and successfully converted the DateTime variable to a string that represents currency. My end goal is to create a clock that counts annual salary on a second-to-second basis.


I’m having some trouble adjusting the parameters. At the moment, my clock begins to count at 00:00:01 however I wish to adjust this to make sure the clock only displays a currency value between the hours of 9:00:00 and 17:00:00 for pragmatic purposes.


Are you able to offer any assistance? I have attached the Form.cs file to this email.


Esentially, I believe I need to change line 54 to represent a subtraction of DateTime HH and HH1 values but am unable to do so because it’s a string. Any help would be great.


Thank you.


Regards,


<sub>Code is as follows:</sub>

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DigitalClock
{
public partial class Form1 : Form
{

Timer t = new Timer();
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//timer interval
t.Interval = 1000; //in milliseconds

t.Tick += new EventHandler(this.t_Tick);

//start timer when form loads
t.Start(); //this will use t_Tick() method
}

//time evernthandler
private void t_Tick(object sender, EventArgs e)
{
//get current time
double HH = Math.Round(8.105 * (DateTime.Now.Hour), 0);
//double HH1 = DateTime.Now.Hour;
double mm = Math.Round(0.135 * (DateTime.Now.Minute), 0);
// double mm1 = DateTime.Now.Minute;
double ss = Math.Round(0.002 * (DateTime.Now.Second), 2);
// double ss1 = DateTime.Now.Second;

//time
string time = "";

//padding leading zero
if(DateTime.Now.Hour < 9)
{
time = "0" + HH1;
}
else if (DateTime.Now.Hour > 9 && DateTime.Now.Hour < 17)
{
time += "0" + HH;
}
else if (DateTime.Now.Hour > 17)
{
time = "0" + HH1;
}
else {
time += HH;
}
time += ":";
if (DateTime.Now.Minute < 10)
{
time = "0" + mm;
}
//else if (DateTime.Now.Hour > 9 && DateTime.Now.Hour < 17 && DateTime.Now.Minute < 10)
//{
//time += "0" + mm;
//}
//else if (DateTime.Now.Hour > 17)
//{
//time = "0" + mm1;
//}
else
{
time += mm;
}
time += ":"; if (ss < 10)
{
time += "0" + ss;
}
else
{
time += ss;
}
time += ":";

//update label
label1.Text = "$" + time;
}
}
}
<sub></sub>

<sub>//Samuel Josling</sub>

Continue reading...
 
Back
Top