Skip to end of metadata
Go to start of metadata

Database Date Format

Dates in the database should be stored in a date/time field, and not in String format. This includes dates that are log entries as this makes it easier to print selective dates.

The dates in the database are in the timezone of the server. We had hoped to store the dates in the database in UTC (GMT) but it appeared to be complex to keep converting the dates and we had trouble with some of the Java conversion methods so we have gone with the server timezone for 2.0.

Date Display As Date

Full date/time formats should be used when displaying dates, rather than just dates, if at all possible.

For JSP pages, use the <lams:Date> tag as this will give us consistency of dates across the system. This tag localises the date format and converts the date to the user's timezone.

For JSON returned dates, the DateUtil.convertToStringForJSON() functions give the same functionality as the <lams:Date> tag, localising the date format and converting the timezone.

The standard way to use it is DateUtil.convertToStringForJSON(someDateObject, request.getLocale()), which will give you a date/time stamp in medium format.

If you need a different format these options are available:

DateUtil.convertToStringForJSON(Date value, Integer style, Locale locale) where style may be DateFormat.SHORT, DateFormat.LONG or DateFormat.LONG. This gives a date/time value.

DateUtil.convertToStringForJSON(Date value, Integer style, Integer type, Locale locale) where

  • style may be DateFormat.SHORT, DateFormat.LONG or DateFormat.LONG.
  • type may be DateUtil.TYPE_BOTH (date and time), DateUtil.TYPE_DATE (date only), DateUtil.TYPE_TIME (time only).

Date Display using Timeago - Java Objects

Timeago gives a relative date display, such as "1 minute ago", "3 minutes ago", "4 days ago". To use Timeago:

  • Include the javascript: <script type="text/javascript" src="<lams:LAMSURL />/includes/javascript/jquery.timeago.js"></script> and also its i18n file jquery.timeago.${localeLanguage}.js (see here or LDEV-3969)
  • Use the lams:Date tag with the timeago option <lams:Date value="${msgDto.message.updated}" timeago="true"/>
  • Initialise timeago in the document.ready function $(document).ready(function() {$("time.timeago").timeago();});

The date/time used as input should be the server time - the fmt:formatDate calls take care of converting to UTC and then timeago compares from UTC.

Date Display using Timeago - JSON

lams:Date relies on having a date object, so if you are passing data via JSON you will want to format the dates as
Strings suitable for timeago in Java. You will need to send the date in two formats - a human readable one and the ISO8601 format for time ago.

For example (from Notebook

Date modifiedDate = (Date) userAndReflection[2];
	DateUtil.convertToStringForJSON(modifiedDate, request.getLocale()));

For example (from

// setting date format to ISO8601 for jquery.timeago
DateFormat dateFormatterTimeAgo = new SimpleDateFormat(DateUtil.ISO8601_FORMAT);

JSONObject responseRow = new JSONObject();
Date attemptTime = response.getAttemptTime();
responseRow.put("attemptTime", DateUtil.convertToStringForJSON(attemptTime, request.getLocale()));
responseRow.put("timeAgo", dateFormatterTimeAgo.format(attemptTime)); 

Using DateUtil.convertToStringForJSON gives you a localised string for the timeago title (the value shown as a tooltip or displayed if there is a timeago error).

Using DateUtil.convertToStringForTimeagoJSON gives you a ISO8601 string for the timeago value.

Then in the jsp javascript that processes the JSON you will have something like:

rows += '<time class="timeago" title="';
rows += userData["attemptTime"];
rows += '" datetime="';
rows += userData["timeAgo"];
rows += '"></time>';
  • No labels