views:

31

answers:

1

A date can be formatted using a e.g. SimpleDateFormat(formatPattern, locale). Is it somehow possible to determine the time period (in seconds) that is represented by formatPattern given a date? E.g. if we have

Date date = new Date(1286488800);
String formatPattern = "yyyy";

is it possible to determine the length of the year (in seconds) represented by formatPattern and in which date lies?

A: 

I think a to use a formatPattern to detect a date range is a bad thing. You need to write a parser for the date pattern. A better idea is to use a drop down list with possible ranges (year, month, week, etc.). Then it not a problem to calculate the length of the current range in seconds.

Horcrux7
Writing a parser is what I want to avoid and thought that maybe the pattern mechanism could somehow be exploited. Too bad it does not seem to be possible :(. Anyway, thanks to all for sharing thoughts on this...