algorithm - Date string format that sorted lexicographically ascending is chronologically descending? -
Encoding in the form of a string in the format YYYY-MM-DD (without separator Or without, like
2014-04-21 ,
2014.04.21 or
20140421 ) has the following attributes:
- Between the date of the calendar Reversed and string is clear to humans (
2014-04-21 obviously represents <21> April 21, 2014)
Meditation Let's always use the same number of numbers for each component of the date (year, month and day) to work, if the number is too small then with leading zero This means that the year can be represented by
YYYY only
99 99 if we want to represent 5 digit years then in my example above Date
02014-04-21 .
Question:
What is a way of encoding calendar dates in the form of asterisk, such as closing the strings sequentially in sequential chronological order?
Ideally, anyone would be easy to change between the calendar's date and format
If this helps you, you may need this restriction Is:
- If you do not manage it, you still want to know your solution.
- I only need to represent dates between January 1, 2001 and December 31, 20 99.
I can come up with:
- Select a maximum representative year ahead of time, e.g. 2100
- In these 3 numbers Anyone is too short, convert year-to-year (2100 years), (13 months), (32-day) as mentioned above and add leading zeros. / Li>
- Thus <21> code becomes
86-09-11
With my solution the main The problem is that it is not clear to humans that
86-09-11
represents on April 21, 2014 .
Note:
- I know that I can correct the
YYYY-MM-DD string in descending order, which is not I'm watching.
String does not have to represent the year, month and day separately in your format. For example, you can encode a date as an integer left for how many days before 1 January 2100 ???? With zero padding on the left.
Even if you can not find the format of any format, which is easily read by humans, I still want to see your answer and as my question Probably want to know many ways.
I'm not looking for a discussion of month / day ambiguity, I think some people get obscure (either 2 January or 1 February)
2001-01-02 Could. But this does not make any difference: the man reading the format will know what the format is (in this case
YYYY-MM-DD ) so there is no ambiguity.
- I know that I can correct the
- I only need to represent dates between January 1, 2001 and December 31, 20 99.
< Li> Putting trimmed strings in a lysxicographically ascending (treating them as simple string, knowing what they represent) them in the chronological order
Comments
Post a Comment