# Class Strftime

java.lang.Object
org.apache.catalina.util.Strftime

public class Strftime extends Object
Converts dates to strings using the same format specifiers as strftime Notes:

- This does not mimic strftime perfectly. Certain strftime commands, are not supported, and will convert as if they were literals.
- Certain complicated commands, like those dealing with the week of the year probably don't have exactly the same behavior as strftime.
- These limitations are due to use SimpleDateTime. If the conversion was done manually, all these limitations could be eliminated.
- The interface looks like a subset of DateFormat. Maybe someday someone will make this class extend DateFormat.

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final SimpleDateFormat`
`simpleDateFormat`
The underlying SimpleDateFormat instance used for date formatting.
`protected static final Properties`
`translate`
Mapping of strftime format specifiers to SimpleDateFormat equivalents.

## Constructor Summary

Constructors
Constructor
Description
`Strftime(String origFormat, Locale locale)`
Create an instance of this date formatting class

## Method Summary

Modifier and Type
Method
Description
`protected String`
`convertDateFormat(String pattern)`
Search the provided pattern and get the C standard Date/Time formatting rules and convert them to the Java equivalent.
`String`
`format(Date date)`
Format the date according to the strftime-style string given in the constructor.
`TimeZone`
`getTimeZone()`
Get the timezone used for formatting conversions
`protected String`
`quote(String str, boolean insideQuotes)`
Quotes a string literal for use in a SimpleDateFormat pattern if it is not already inside quotes.
`void`
`setTimeZone(TimeZone timeZone)`
Change the timezone used to format dates
`protected boolean`
`translateCommand(StringBuilder buf, String pattern, int index, boolean oldInside)`
Try to get the Java Date/Time formatting associated with the C standard provided.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### translate

protected static final Properties translate
Mapping of strftime format specifiers to SimpleDateFormat equivalents.

### simpleDateFormat

protected final SimpleDateFormat simpleDateFormat
The underlying SimpleDateFormat instance used for date formatting.

## Constructor Details

### Strftime

public Strftime(String origFormat, Locale locale)
Create an instance of this date formatting class

Parameters:
  `origFormat` - the strftime-style formatting string
  `locale` - the locale to use for locale-specific conversions

## Method Details

### format

public String format(Date date)
Format the date according to the strftime-style string given in the constructor.

Parameters:
  `date` - the date to format
Returns:
  the formatted date

### getTimeZone

public TimeZone getTimeZone()
Get the timezone used for formatting conversions

Returns:
  the timezone

### setTimeZone

public void setTimeZone(TimeZone timeZone)
Change the timezone used to format dates

Parameters:
  `timeZone` - The new time zone
See Also:
  - `DateFormat.setTimeZone(TimeZone)`

### convertDateFormat

protected String convertDateFormat(String pattern)
Search the provided pattern and get the C standard Date/Time formatting rules and convert them to the Java equivalent.

Parameters:
  `pattern` - The pattern to search
Returns:
  The modified pattern

### quote

protected String quote(String str, boolean insideQuotes)
Quotes a string literal for use in a SimpleDateFormat pattern if it is not already inside quotes.

Parameters:
  `str` - the string to quote
  `insideQuotes` - whether the current position is inside quotes
Returns:
  the quoted string

### translateCommand

protected boolean translateCommand(StringBuilder buf, String pattern, int index, boolean oldInside)
Try to get the Java Date/Time formatting associated with the C standard provided.

Parameters:
  `buf` - The buffer
  `pattern` - The date/time pattern
  `index` - The char index
  `oldInside` - Flag value
Returns:
  True if new is inside buffer