[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Accessing OS time format

Hi, sorry for the late reply,

API that returns the OS date format seems a bit outside of DateTime's role.
However, API that returned the date in a String that matched this format
seems reasonable.  I've found this currently logged as
https://bugs.eclipse.org/bugs/show_bug.cgi?id=220068 .

Grant


"Will Horn" <will.horn@xxxxxxxxx> wrote in message
news:g43ipe$e1t$1@xxxxxxxxxxxxxxxxxxxx
> I use the DateTime for data entry code in my RCP application (on Windows),
The widget displays the
> time in the format specified in the Windows Control panel.  I store the
date in XMLGregorianCalendar
> and need to display is later in a table form.  I have not found any Java
support for obtaining the
> OS time format and I was wondering if this could be made available in SWT.
>
> The code exists internally in DateTime.getTimeFormat (at least for
Windows).  Is this a reasonable
> enhancement request?
>
> By the way, copying the code from DateTime seems a way to get access now
(totally discouraged,
> unsupported, and non-portable, I know):
>
>      public static void main(String[] args) {
> TCHAR tchar = new TCHAR (getCodePage (), 80);
> int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT,
OS.LOCALE_STIMEFORMAT, tchar, 80);
> System.out.println(size > 0 ? tchar.toString (0, size - 1) : "h:mm:ss
tt"); //$NON-NLS-1$
>      }
>
>      static int getCodePage () {
> if (OS.IsUnicode) return OS.CP_ACP;
> int /*long*/ hFont = OS.SendMessage (new Shell().handle, OS.WM_GETFONT, 0,
0);
> LOGFONT logFont = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA
();
> OS.GetObject (hFont, LOGFONT.sizeof, logFont);
> int cs = logFont.lfCharSet & 0xFF;
> int [] lpCs = new int [8];
> if (OS.TranslateCharsetInfo (cs, lpCs, OS.TCI_SRCCHARSET)) {
> return lpCs [1];
> }
> return OS.GetACP ();
>      }