CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Location
    Karnataka,India
    Posts
    10

    API to Change the System Date Format

    Hi,
    Friends, can u please let me the know the API through which i can change the System Date Format.
    Thanks & regards,
    Sudhakara.T.P.



  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: API to Change the System Date Format

    This is done in the registry, alter the following keys

    HKEY_CURRENT_USER\Control Panel\International\sShortDate
    HKEY_CURRENT_USER\Control Panel\International\sLongDate

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Apr 2001
    Location
    Karnataka,India
    Posts
    10

    Re: API to Change the System Date Format

    Hi,
    thanks & regards,
    sudhi.


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: API to Change the System Date Format

    'The Win32 API includes native functions that
    'allow you To change a file's properties, such as time and date, without a
    'third-party DLL.

    Option Explicit
    '
    Private Type FILETIME
    dwLowDate As Long
    dwHighDate As Long
    End Type

    Private Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMillisecs As Integer
    End Type

    Private Const FILE_SHARE_READ = &H1
    Private Const FILE_SHARE_WRITE = &H2
    Private Const GENERIC_WRITE = &H40000000
    Private Const OPEN_EXISTING = 3

    Private Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long
    Private Declare Function CreateFile Lib "kernel32" _
    Alias "CreateFileA" (ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, ByVal dwShareMode _
    As Long, ByVal lpSecurityAttributes As Long, ByVal _
    dwCreationDisposition As Long, ByVal _
    dwFlagsAndAttributes As Long, ByVal hTemplateFile _
    As Long) As Long

    Private Declare Function LocalFileTimeToFileTime Lib _
    "kernel32" (lpLocalFileTime As FILETIME, lpFileTime _
    As FILETIME) As Long
    Private Declare Function SetFileTime Lib "kernel32" _
    (ByVal hFile As Long, ByVal MullP As Long, ByVal _
    NullP2 As Long, lpLastWriteTime As FILETIME) As Long
    Private Declare Function SystemTimeToFileTime Lib _
    "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime _
    As FILETIME) As Long

    Sub Main()

    Call SetFileDate("c:\autoexec.bat", "10/16/96 12:30 pm")

    End Sub


    Sub SetFileDate(sFileName As String, sDate As String)

    Dim hFile As Long
    Dim lResult As Long
    Dim udtSysTime As SYSTEMTIME
    Dim udtFileTime As FILETIME
    Dim udtLocalTime As FILETIME

    With udtSysTime
    .wYear = Year(sDate)
    .wMonth = Month(sDate)
    .wDay = Day(sDate)
    .wDayOfWeek = WeekDay(sDate) - 1
    .wHour = Hour(sDate)
    .wMinute = Minute(sDate)
    .wSecond = Second(sDate)
    End With

    lResult = SystemTimeToFileTime(udtSysTime, _
    udtLocalTime)
    lResult = LocalFileTimeToFileTime(udtLocalTime, _
    udtFileTime)

    hFile = CreateFile(sFileName, GENERIC_WRITE, _
    FILE_SHARE_READ _
    Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, _
    0, 0)

    lResult = SetFileTime(hFile, ByVal 0&, ByVal 0&, _
    udtFileTime)

    Call CloseHandle(hFile)

    End Sub



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured