【VB声明】
  Private Declare Sub GetSystemTime Lib "kernel32" Alias "GetSystemTime" (lpSystemTime As SYSTEMTIME)【说明】
  在一个SYSTEMTIME中载入当前系统时间,这个时间采用的是“协同世界时间”(即UTC,也叫做GMT)格式 【参数表】
  lpSystemTime ---  SYSTEMTIME,随同当前时间载入的结构

解决方案 »

  1.   

    Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
    Private Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
    End Type
    Private Sub Form_Load()
        'KPD-Team 1998
        'URL: http://www.allapi.net/
        '[email protected]
        Dim SysTime As SYSTEMTIME
        'Set the graphical mode to persistent
        Me.AutoRedraw = True
        'Get the system time
        GetSystemTime SysTime
        'Print it to the form
        Me.Print "The System Date is:" & SysTime.wMonth & "-" & SysTime.wDay & "-" & SysTime.wYear
        Me.Print "The System Time is:" & SysTime.wHour & ":" & SysTime.wMinute & ":" & SysTime.wSecond
    End Sub
      

  2.   

    Private Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
    End Type
    Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
    Private Sub Form_Load()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim lpSystemTime As SYSTEMTIME
        lpSystemTime.wYear = 2000
        lpSystemTime.wMonth = 1
        lpSystemTime.wDayOfWeek = -1
        lpSystemTime.wDay = 24
        lpSystemTime.wHour = 23
        lpSystemTime.wMinute = 26
        lpSystemTime.wSecond = 0
        lpSystemTime.wMilliseconds = 0
        'set the new time
        SetSystemTime lpSystemTime
    End Sub
      

  3.   

    對不起﹐我是想問如何獲得和個性系統簡短日期格式. 因為我做的程序不能使用系統默認的日期格式﹐我要用dd/mm/yyyy ﹐我想在我的程序運行時改成dd/mm/yyyy,而結束后恢復到系統原來的日期格式.
      

  4.   

    Windows的系统日期格式在注册表中存着,你必须使用API修改注册表中的设置,才能达到那个目的,用其它的API函数好像不能解决这个问题,我原来为这个问题郁闷了好久,连用友的财务软件都没有搞定,在运行前提示用户手工修改日期格式,受不了!呵呵
    不传之密噢!
      

  5.   

    呵呵用format来解决Format 函数示例
    本示例显示用 Format 函数做格式化输出的不同用法。对于日期分隔号(/),时间分隔号(:),以及 AM/ PM 等文本而言,其真正的显示格式会因计算机上的国际标准不同而有所差异。在开发阶段,日期与时间是以短日期的格式,配合代码的国际标准来显示的。而在运行时,短日期则是根据系统的国际标准而定,而系统的国际标准和代码的国际标准可能并不相同。本示例中是假设国际标准为 English/United States。MyTime 及 MyDate 在开发环境下,使用系统的短日期设置显示出来的。Dim MyTime, MyDate, MyStr
    MyTime = #17:04:23#
    MyDate = #January 27, 1993#' 以系统设置的长时间格式返回当前系统时间。
    MyStr = Format(Time, "Long Time")' 以系统设置的长日期格式返回当前系统日期。
    MyStr = Format(Date, "Long Date")MyStr = Format(MyTime, "h:m:s")   ' 返回 "17:4:23"。
    MyStr = Format(MyTime, "hh:mm:ss AMPM")   ' 返回 "05:04:23 PM"。
    MyStr = Format(MyDate, "dddd, mmm d yyyy")   ' 返回 "Wednesday, Jan 27 1993"。
    ' 如果没有指定格式,则返回字符串。
    MyStr = Format(23)   ' 返回 "23"。' 用户自定义的格式。
    MyStr = Format(5459.4, "##,##0。00")   ' 返回 "5,459.40"。
    MyStr = Format(334。9, "###0。00")   ' 返回 "334.90"。
    MyStr = Format(5, "0。00%")   ' 返回 "500.00%"。
    MyStr = Format("HELLO", "<")   ' 返回 "hello"。
    MyStr = Format("This is it", ">")   ' 返回 "THIS IS IT"。
      

  6.   

    获取和设置系统的簡短日期格式?没问题,这个足够用!'--------------------------------------------------------
    'Purpose: Change system shortdate format
    'Example: Call mdlChangeSystemDateFormat("dd/MMM/yyyy")
    '--------------------------------------------------------Public Const LOCALE_SSHORTDATE As Long = &H1F
    Public Const LOCALE_USER_DEFAULT As Long = &H400Public 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 LongPublic Function mdlChangeSystemDateFormat(strFormat As String) As Boolean    Dim strShortDateFormat As String, strBuffer As String
        Dim lBuffSize As Long, lRetVal As Long
        
        lBuffSize = 256
        strBuffer = String(lBuffSize, vbNullChar)
        
        'Get current short date format
        lRetVal = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strBuffer, lBuffSize)
        
        If lRetVal > 0 Then
            strShortDateFormat = Left(strBuffer, lRetVal - 1)
        Else
            Exit Function
        End If
        
        'If current short date format is different from your format, change it.
        'Note: MMM should be used in capital for month,small m are for minutes
        If UCase(strShortDateFormat) <> UCase(strFormat) Then
            lRetVal = SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strFormat)
        End If
        
        If lRetVal > 0 Then mdlChangeSystemDateFormat = True
    End Function