vb.net | Date in more user friendly format

~OSD~ 1,901 Reputation points
2023-03-20T06:56:31.5433333+00:00

Hi,

is it possible to get the date in more user friendly?

Dim BIOSInfo As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_BIOS")

queryBIOS("ReleaseDate")

20221219000000.000000+000 Dim OSInfo As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_OperatingSystem")

queryOSInfo("InstallDate")

20220502080901.000000+060

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,320 questions
0 comments No comments
{count} votes

Accepted answer
  1. LesHay 7,096 Reputation points
    2023-03-20T11:25:42.16+00:00

    Hi

    OR,

    		' From: https://stackoverflow.com/questions/170617/how-do-i-find-the-install-time-and-date-of-windows
    
    		' Needs Imports System.Management
    		Dim dtmInstallDate As DateTime
    		Dim oSearcher As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
    		For Each oMgmtObj As ManagementObject In oSearcher.Get
    			dtmInstallDate = ManagementDateTimeConverter.ToDateTime(CStr(oMgmtObj("InstallDate")))
    		Next
    
    
    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 19,931 Reputation points Microsoft Vendor
    2023-03-20T09:13:29.58+00:00

    Hi, welcome to Microsoft Q&A. The specific format needs to refer to the motherboard manufacturer. The following code intercepts the part of the data before . to format the datetime.

            Dim formatString As String = "yyyyMMddHHmmss"
            Dim str As String = "20220502080901.000000+060"
            Dim dt As DateTime = DateTime.ParseExact(str.Split("+")(0), formatString, Nothing)
            MessageBox.Show(dt)
    

    Best Regards.
    Jiachen Li
    ----------
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.