See Java documentation for package java.time and java.time.format for more ideas

The timestamp of the event when the incoming value object is created is stored in the value object. This time is the milliseconds from the Java epoch of 1970-01-01T00:00:00Z.

timestamp = incomingValue.getTimeMillis();
 
//convert time in millseconds to a local time
valueObjectTime = java.time.Instant.ofEpochMilli(timestamp);
localZonedDateTime = java.time.LocalDateTime.ofInstant(valueObjectTime, java.time.ZoneId.systemDefault());
 
//print this as a local time and date using a time formatter
df=java.time.format.DateTimeFormatter.ofLocalizedDateTime(java.time.format.FormatStyle.MEDIUM); 
 
//use the formatter to make the output human readable
print("time of value object is "+df.format(localZonedDateTime));
output=df.format(localZonedDateTime);

For log4j logging, use a date formatter %d in the appender layout, for example:

	    <layout class="org.apache.log4j.PatternLayout">
		  <param name="ConversionPattern"  value="%d{ISO8601} %m %n" />
	    </layout>

In a script the current time can be printed using:

 //simple formatter for the time
 df=java.time.format.DateTimeFormatter.ofPattern("HH:mm:ss"); 
 timenow =  java.time.LocalDateTime.now();
 print(df.format(timenow)+" Time of Event");
  • dateandtimecalculationscripts.txt
  • Last modified: 2021/07/25 16:14
  • by wikiadmin