Advertisement
Guest User

Untitled

a guest
Jan 16th, 2013
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1.  
  2. public static String format(Date date, Locale locale, FORMAT_TYPE type) {
  3. log.debug("Formatting date: " + date + " with locale " + locale);
  4.  
  5. DateFormat dateFormat = null;
  6.  
  7. if (type == FORMAT_TYPE.TIMESTAMP) {
  8. String dateTimeFormat = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GLOBAL_PROPERTY_DATEANDTIME_DISPLAY_FORMAT, null);
  9. if (StringUtils.isEmpty(dateTimeFormat))
  10. dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
  11. else
  12. dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(dateTimeFormat), locale);
  13. }
  14. else if (type == FORMAT_TYPE.TIME) {
  15. String timeFormat = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GLOBAL_PROPERTY_TIME_DISPLAY_FORMAT, null);
  16. if (StringUtils.isEmpty(timeFormat))
  17. dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
  18. else
  19. dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(timeFormat), locale);
  20. }
  21. else {
  22. //if (type == FORMAT_TYPE.DATE) (default)
  23. dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
  24. }
  25. return date == null ? "" : dateFormat.format(date);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement