0

Datebox adds 1900 to year when year<100

asked 2016-02-10 14:29:10 +0800

BasClaessenStedin gravatar image BasClaessenStedin
1

The standard ZK datebox adds 1900 to the year part when the year<100. Is this a bug?

This behavior can be reproduced with the code fragment below:

<?xml version="1.0" encoding="UTF-8"?>
<zk>
    <zscript><![CDATA[
        import java.text.SimpleDateFormat;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date dateYearAfter100= formatter.parse("2010-10-25");
        Date dateYearBefore100= formatter.parse("0080-10-25");
]]></zscript>
    <label value="${dateYearAfter100.toString()}"/>
    <datebox value="${dateYearAfter100}" readonly="true"/>
    <label value="${dateYearBefore100.toString()}"/>
    <datebox value="${dateYearBefore100}" readonly="true"/>
</zk>
delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-02-14 09:22:50 +0800

Darksu gravatar image Darksu
1991 1 4

Darksu

Hello BasClaessenStedin,

It has to do with the Java Date implementation as shown from the official documentation below:

http://docs.oracle.com/javase/6/docs/api/java/util/Date.html#getYear(%29))

A year y is represented by the integer y - 1900

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2016-02-15 11:08:30 +0800

BasClaessenStedin gravatar image BasClaessenStedin
1

Hi Darksu,

A date with a year that is equal to 101 displays correctly. Can you explain that behaviour?

Kind regards,

Bas

<?xml version="1.0" encoding="UTF-8"?>
<zk>
    <zscript><![CDATA[
        import java.text.SimpleDateFormat;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date dateYearAfter100= formatter.parse("2010-10-25");
        Date dateYearBefore100= formatter.parse("0080-10-25");
        Date dateYear101= formatter.parse("0101-10-25");
]]></zscript>
    <label value="${dateYearAfter100.toString()}"/>
    <datebox value="${dateYearAfter100}" readonly="true"/>
    <label value="${dateYearBefore100.toString()}"/>
    <datebox value="${dateYearBefore100}" readonly="true"/>
    <label value="${dateYear101.toString()}"/>
    <datebox value="${dateYear101}" readonly="true"/>
</zk>
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-02-10 14:29:10 +0800

Seen: 13 times

Last updated: Feb 15 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More