Format Date Time

One of the way to format a date or a time is using SimpleDateFormat class object:

private SimpleDateFormat sdf;

After declaring sdf object, it is necessary to specify a time zone and a date format:

 sdf = new SimpleDateFormat("HH:mm");
 sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

Let's say that we need to display last tick hour and minutes time:

 long lastTickTime = history.getLastTick(instrument).getTime();
 sdf.format(lastTickTime);

format() function will return last tick time as formatted string;

For more detailed SimpleDateFormat description see SimpleDateFormat.

The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.