Time Formatting - Please help!

  • Thread starter Thread starter PJHORNSA
  • Start date Start date
P

PJHORNSA

Hi all,

I got a problem.. I want to format the time into a decimal value.. The
code that I used worked fine for some time but now it does not want to
work.... If any one can help me or give me alternative code... Thanks
in advance

Code:
++++

decimal.Parse(DateTime.Now.TimeOfDay.ToString().Replace(":","").Replace(".","").Remove(7,DateTime.Now.TimeOfDay.ToString().Length
- 7).Trim());



Error:
++++

Additional information: Index and count must refer to a location within
the string.

All help would be appreciated.
Paul
 
Hi,



PJHORNSA said:
Hi all,

I got a problem.. I want to format the time into a decimal value.. The
code that I used worked fine for some time but now it does not want to
work.... If any one can help me or give me alternative code... Thanks
in advance

Code:
++++

decimal.Parse(DateTime.Now.TimeOfDay.ToString().Replace(":","").Replace(".","").Remove(7,DateTime.Now.TimeOfDay.ToString().Length
- 7).Trim());


That is terrible complex, just use ToString with a custom format and parse
it:

decimal.Parse( DateTime.Now.ToString("HHMMdd",
DateTimeFormatInfo.InvariantInfo );

note:
I did not tried to understand what format you want, just check MSDN for the
correct format string
 
Back
Top