skij
asked on
ASP.NET/VB: Convert Date and Time to YYYY-MM-DDTHH:MM:SS
Using ASP.NET/VB, how can I convert a string from this format:
5/25/2015 3:45:27 PM
to this format:
2015-05-25T14:59:04
I want the time format to match the W3C Datetime specification.
https://www.w3.org/TR/NOTE-datetime
5/25/2015 3:45:27 PM
to this format:
2015-05-25T14:59:04
I want the time format to match the W3C Datetime specification.
https://www.w3.org/TR/NOTE-datetime
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured it out, based on your help, thanks.
Imports System.Web
Imports System.Globalization
Partial Class _Default
Inherits CMSBasePage
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim TS as String
Response.Write( w3cdate("5/25/2015 3:45:27 PM") )
Response.End()
End Sub
Protected Function w3cdate(TS As String)
Dim dt As DateTime
Dim provider As CultureInfo = CultureInfo.InvariantCulture
Dim datestring As String = "M/d/yyyy h:mm:ss tt"
dt = Date.ParseExact(TS, datestring, provider)
return dt.ToString("yyyy-MM-ddTHH:mm:ss")
End Function
End Class
ASKER
Open in new window