روش تعويض فرمت تاريخ كامپيوتر

Amin_vb

Member
با اين كد شما مي‌توانيد فرمت تاريخ كامپيوتر خود را در ويژوال بيسيك عوض نماييد.

ابتدا كد زير را در يك ماژول وارد نماييد.
کد:
Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const LOCALE_USER_DEFAULT As Long = &H400

Public Declare Function GetLocaleInfo Lib "kernel32" _
    Alias "GetLocaleInfoA" (ByVal lLocale As Long, _
        ByVal lLocaleType As Long, ByVal sLCData As String, _
        ByVal lBufferLength As Long) As Long
Public Declare Function SetLocaleInfo Lib "kernel32" _
    Alias "SetLocaleInfoA" (ByVal Locale As Long, _
        ByVal LCType As Long, ByVal lpLCData As String) As Long

حال كد زير را در فرم برنامه خود وارد كنيد.

کد:
'put this code at form
'i have used for short date format similarly it can be used for long 
'date format

    Dim shortDateFormat As String
    Dim lBuffSize As String
    Dim sBuffer As String
    Dim lRetGet As Long
    Dim lRetSet As Long
    
    lBuffSize = 256
    sBuffer = String$(lBuffSize, vbNullChar)
    'get the date information in buffer
    lRetGet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, sBuffer, lBuffSize)
  
    If lRetGet > 0 Then
        shortDateFormat = Left$(sBuffer, lRetGet - 1)
        'this is the existing format of machine
   End If
    'to change the format if doesn't matches ur format
	'MM should be used in capital for monyhs,small m are for minutes
    If LCase(shortDateFormat) <> "dd/mm/yyyy" Then
        lRetSet = SetLocaleInfo(LOCALE_USER_DEFAULT,_ LOCALE_SSHORTDATE, "dd/MM/yyyy")
'on sucess lretset have value greater than 0
        If lRetSet <= 0 Then
             msgbox "date format not changed
        End If
    End If
 

جدیدترین ارسال ها

بالا