Package jade.lang.acl
Class ISO8601
- java.lang.Object
-
- jade.lang.acl.ISO8601
-
public class ISO8601 extends Object
This class contains a set of static methods that convert to/from the Date Time format adopted by FIPA. The FIPA format is based on ISO8601, with the addition of milliseconds. Using thejava.text.SimpleDateFormatnotation, it is:yyyyMMdd'T'HHmmssSSS'Z', where the'T'serves to separate the Day from the Time, and the'Z'indicates that the time is in UTC. The FIPA specs permit either local or UTC time, however, they do express a preference for UTC time (this is particularly helpful when passing messages between agents running on machines in different timezones).- Older versions of this code:
- read DateTime as local time
- wrote DateTime as local time
- Current versions of this code:
- read DateTime in both local time and UTC time
- write DateTime as UTC time by default (can generate local time
if
toString(false)is called).
- Version:
- $Date$ $Revision$ Modified by:
- Author:
- Fabio Bellifemine - CSELT, Craig Sayers, HP Labs, Palo Alto, California
- Older versions of this code:
-
-
Constructor Summary
Constructors Constructor Description ISO8601()Default constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidmain(String[] argv)The main is here only for debugging.static DatetoDate(String dateTimeToken)This method converts a FIPA DateTime token to ajava.util.Date.static StringtoRelativeTimeString(long millisec)this method converts into a string in ISO8601 format representing relative time from the current timestatic StringtoString(Date d)This method converts ajava.util.Dateinto a FIPA DateTime token by using the UTC time.static StringtoString(Date d, boolean useUTCtime)This method converts ajava.util.Dateinto a FIPA DateTime token.
-
-
-
Method Detail
-
toDate
public static Date toDate(String dateTimeToken) throws Exception
This method converts a FIPA DateTime token to ajava.util.Date. It will accept both local and UTC time formats.- Returns:
- an absolute value of DateTime
- Throws:
an- Exception if the String is not a valid dateTimeException
-
toString
public static String toString(Date d, boolean useUTCtime)
This method converts ajava.util.Dateinto a FIPA DateTime token. Note: the current default behaviour is to generate dates in UTC time. seeISO8601.useUTCtimefor details.- Parameters:
useUTCtime- controls the style used bytoString, 'true' generates tokens using UTC time, 'false' using local time. If you need to send messages to agents compiled with older versions of Jade, then set this tofalse.- Returns:
- a String, e.g. "19640625T073000000Z" to represent 7:30AM on the 25th of June of 1964, UTC time.
-
toString
public static String toString(Date d)
This method converts ajava.util.Dateinto a FIPA DateTime token by using the UTC time.- Returns:
- a String, e.g. "19640625T073000000Z" to represent 7:30AM on the 25th of June of 1964, UTC time.
-
toRelativeTimeString
public static String toRelativeTimeString(long millisec)
this method converts into a string in ISO8601 format representing relative time from the current time- Parameters:
millisec- is the number of milliseconds from now- Returns:
- a String, e.g. "+00000000T010000000" to represent one hour from now
-
main
public static void main(String[] argv)
The main is here only for debugging. You can test your conversion by executing the following command:java jade.lang.acl.ISO8601
-
-