Etienne
Etienne

Reputation: 7201

How to format a date in vb.net

I want to display my date like so in VB.NET

2008/01/22 14:23:15

How is this done in code?

This does not give me enough: lblDate.Text = Today.Date

Upvotes: 1

Views: 26847

Answers (3)

Binary Worrier
Binary Worrier

Reputation: 51711

Try

lblDate.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")

Upvotes: 9

Amit
Amit

Reputation: 7035

Please try : Date.Now

Upvotes: 0

Dan Tao
Dan Tao

Reputation: 128327

This should display the way you want:

Dim formattedDate As String = Date.Today.ToString("yyyy/MM/dd HH:mm:ss")

And see Custom DateTime Format Strings for a complete reference.

Upvotes: 9

Related Questions