C# – .NET Culture-dependent ‘Today’ string

.netc++datetimemonthcalendar

I am writing a month calendar-style control, and need to display a string that indicates today's date. So on an English-culture machine it would show 'Today : 11/02/2009'.

If a different culture happens to be used, such as French, then I would like to use the French word for 'Today'.

Does the .NET platform expose this word as part of the culture information so I can retrieve it automatically? I cannot find anything exposed but maybe I am not looking in the right place.

Best Solution

Old.. but still useful (how old? VB6 old).

Basically Windows keeps a localized version of "Today" in Comctl32.dll. You can fish it out with a a loadstringex call:

Private Const IDM_TODAY As Long = 4163
Private Const IDM_GOTODAY As Long = 4164

Public Function GetTodayLocalized(ByVal LocaleId As Long) As String
    Static hComCtl32 As Long
    Static hComCtl32Initialized As Boolean
    Static hComCtl32MustBeFreed As Boolean

    Dim s As String

    If Not hComCtl32Initialized Then
        hComCtl32 = GetModuleHandle("Comctl32.dll")
        If hComCtl32 <> 0 Then
            hComCtl32MustBeFreed = False
            hComCtl32Initialized = True
        Else
            hComCtl32 = LoadLibrary("Comctl32.Dll")
            If Not hComCtl32 = 0 Then
                hComCtl32MustBeFreed = True
                hComCtl32Initialized = True
            End If
        End If
    End If

    If hComCtl32Initialized = False Then
        s = "Today"
    Else
        s = LoadStringEx(hComCtl32, IDM_TODAY, LocaleId)
        If s = "" Then
            s = "Today"
        End If
    End If

    If hComCtl32MustBeFreed Then
        FreeLibrary hComCtl32
        hComCtl32MustBeFreed = False
        hComCtl32Initialized = False
        hComCtl32 = 0
    End If

    s = Replace(s, "&", "")
    If Right(s, 1) = ":" Then
        s = Left(s, Len(s) - 1)
    End If

    GetTodayLocalized = s
End Function