Showing posts with label locale. Show all posts
Showing posts with label locale. Show all posts

Tuesday, October 27, 2015

Locale settings for date and time in IBM Domino and Notes

Recently we setup 2 new IBM Domino servers and today I found an issue related to how we display time in our application. The 12-hours format was used (with AM or PM). I've checked OS date settings and they were right so I started to google and found out that in order to change locale settings to 24-hours you have either update notes.ini with a ClockType variable or change register.

I went with notes.ini (feel more safe with it). Below few variables that control date/time format output.
 DateOrder=YMD  
 DateSeparator=.  
 TimeSeparator=:  
 CLOCKTYPE=24_HOUR  

It is also possible for windows OS to change register (but I personally do not like that).
 HKEY_USERS\.DEFAULT\Control Panel\International\iDate  
 HKEY_USERS\.DEFAULT\Control Panel\International\iTime  
 HKEY_CURRENT_USER\Control Panel\International\iDate  
 HKEY_CURRENT_USER\Control Panel\International\iTime  

You may find more information about it in article Timely information in NOTES.INI

Related topics:
Format datetime object in Lotus Script

Saturday, July 04, 2015

Transformation of String into Date respecting Locale

Let's say you need to parse a string into date and it is localized string (f.x. name of month on local language). In past I would definitely define an array with months and then parse a String to get a number of my month and then build a Date object. In Java it's pretty simple (almost 1 line of code).

Locale approach

package parser;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class parser {

 public static void main(String[] args) throws ParseException {
  Locale locale = new Locale("ru");
  Date date = convertStringToDate("19 Сентября 2004", "d MMMM yyyy", locale);
  System.out.println(date); // Sun Sep 19 00:00:00 CEST 2004
 }
 
 public static java.util.Date convertStringToDate(String dateString, String format, Locale locale) throws ParseException {
  return new SimpleDateFormat("d MMMM yyyy", locale).parse(dateString);
 }
}
Alternatively, if you need to define months yourself use DateFormatSymbols

Define symbols in DateFormatSymbols

package parser;

import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class parser {

 public static void main(String[] args) throws ParseException {
  String months[] = {"Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"};
  DateFormatSymbols dfs = new DateFormatSymbols();
  dfs.setMonths(months);
  
  SimpleDateFormat sdf = new SimpleDateFormat("d MMMM yyyy");
  sdf.setDateFormatSymbols(dfs);
  System.out.print(sdf.parse("19 Сентября 2004")); // Sun Sep 19 00:00:00 CEST 2004
 }
}