Jump to content
Can't remember your login details? Read more... ×
Sign in to follow this  
SquallStrife

VB.Net Format function not playing ball.

Recommended Posts

Dim Timenow as Date
Dim Timeat5 as Date
Dim Timetill as TimeSpan

Timenow = Now
Timeat5 = Today.Addhours(17)
Timetill = Timeat5.Subtract(Timenow)

Console.Writeline(String.Format("{0:HH:mm:ss} to go!",Timetill))

The above code works, but it always shows seconds with decimal places, which I don't want. Is there a way to prevent this? I'd have thought the Format function would only show the two digits, in line with the "ss".

 

Actually, it's ignoring the formatting all together. What's the go?

Share this post


Link to post
Share on other sites

Dim Timenow as Date
Dim Timeat5 as Date
Dim Timetill as TimeSpan

Timenow = Now
Timeat5 = Today.Addhours(17)
Timetill = Timeat5.Subtract(Timenow)

Console.Writeline(String.Format("{0:HH:mm:ss} to go!",Timetill))

The above code works, but it always shows seconds with decimal places, which I don't want. Is there a way to prevent this? I'd have thought the Format function would only show the two digits, in line with the "ss".

 

Actually, it's ignoring the formatting all together. What's the go?

I don't use VB.NET, I spend most of my time using VBA. I'd convert timetill without the "to go!" and appended "to go!" to the end result.

I won't give any code since VBA code isn't VB.NET code.

Share this post


Link to post
Share on other sites

I don't use VB.NET, I spend most of my time using VBA. I'd convert timetill without the "to go!" and appended "to go!" to the end result.

I wouldn't. The reason being strings are immutable and concatenating "4:15:40" and " to go!" will require more memory than just "injecting" into string format. Though, the difference is so tiny that favouring readability over performance is fine :)

 

SquallStrife. TimeSpan != DateTime. It's like trying to format 4.323230 with HH:mm:ss

 

I'd use string.Format("{0}:{1}:{2} to go!", Timetill.Hours, Timetill.Minutes, Timetill.Seconds)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×