org.graphstream.util.time
Class ISODateIO

java.lang.Object
  extended by org.graphstream.util.time.ISODateIO

public class ISODateIO
extends Object

Scanner for date in ISO/IEC 9899:1999 format. The scanner takes a format and then is able to parse timestamp in the given format. The parse() return a Calendar for convenience. Format of the scanner can be composed of %? directive which define components of the time. These directives are listed below. For example, the format "%F %T", which is equivalent to "%Y-%m-%d %H:%M:%S" can parse the following timestamp: "2010-12-09 03:45:39";

%a
locale's abbreviated weekday name
%A
locale's weekday name
%b
locale's abbreviated month name
%B
locale's month name
%c
locale's date and time representation
%C
two first digits of full year as an integer (00-99)
%d
day of the month (01-31)
%D
%m/%d/%y
%e
day of the month (1-31)
%F
%Y-%m-%d
%g
last 2 digits of the week-based year (00-99)
%G
"week-based year as a decimal number
%h
%b
%H
hour (24-hour clock) as a decimal number (00-23)
%I
hour (12-hour clock) as a decimal number (01-12)
%j
day of the year as a decimal number (001-366)
%k
milliseconds as a decimal number (001-999)
%K
milliseconds since the epoch
%m
month as a decimal number (01-12)
%M
minute as a decimal number (00-59)
%n
\n
%p
locale-s equivalent of the AM/PM
%r
locale's 12-hour clock time
%R
%H:%M
%S
second as a decimal number (00-60)
%t
\t
%T
%H:%M:%S
%u
ISO 8601 weekday as a decimal number (1-7)
%U
week number of the year as a decimal number (00-53)
%V
ISO 8601 week number as a decimal number (01-53)
%w
weekday as a decimal number (0-6)
%W
week number of the year as a decimal number (00-53)
%x
locale's date representation
%X
locale's time representation
%y
last 2 digits of the year as a decimal number (00-99)
%Y
year as a decimal number
%z
offset from UTC in the ISO 8601 format
%Z
locale's time zone name of abbreviation or empty

Author:
Guilhelm Savin

Constructor Summary
ISODateIO()
          Create a scanner with default format "%K".
ISODateIO(String format)
          Create a new scanner with a given format.
 
Method Summary
 Pattern getPattern()
          Get the current pattern used to parse timestamp.
 Calendar parse(String time)
          Parse a string which should be in the scanner format.
 void setFormat(String format)
          Set the format of this scanner.
 String toString(Calendar calendar)
          Convert a calendar into a string according to the format of this object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ISODateIO

public ISODateIO()
          throws ParseException
Create a scanner with default format "%K".

Throws:
ParseException

ISODateIO

public ISODateIO(String format)
          throws ParseException
Create a new scanner with a given format.

Parameters:
format - format of the scanner.
Throws:
ParseException - if bad directives found
Method Detail

getPattern

public Pattern getPattern()
Get the current pattern used to parse timestamp.

Returns:
a regular expression as a string

setFormat

public void setFormat(String format)
               throws ParseException
Set the format of this scanner.

Parameters:
format - new format of the scanner
Throws:
ParseException - if an error is found in the new format

parse

public Calendar parse(String time)
Parse a string which should be in the scanner format. If not, null is returned.

Parameters:
time - timestamp in the scanner format
Returns:
a calendar modeling the time value or null if invalid format

toString

public String toString(Calendar calendar)
Convert a calendar into a string according to the format of this object.

Parameters:
calendar - the calendar to convert
Returns:
a string modeling the calendar.


Copyright © 2012. All Rights Reserved.