@Test
    public void testGetSetDate() {
        Metadata meta = new Metadata();
        long hour = 60 * 60 * 1000;

        // Isn't initially set, will get null back
        assertEquals(null, meta.get(TikaCoreProperties.CREATED));
        assertEquals(null, meta.getInt(TikaCoreProperties.CREATED));

        // Can only set as a single valued date
        try {
            meta.set(Metadata.BITS_PER_SAMPLE, new Date(1000));
            fail("Shouldn't be able to set a multi valued property as a date");
        } catch (PropertyTypeException e) {
            //swallow
        }
        try {
            meta.set(Metadata.IMAGE_WIDTH, new Date(1000));
            fail("Shouldn't be able to set an int property as an date");
        } catch (PropertyTypeException e) {
            //swallow
        }

        // Can set it and retrieve it
        meta.set(TikaCoreProperties.CREATED, new Date(1000));
        assertEquals("1970-01-01T00:00:01Z", meta.get(TikaCoreProperties.CREATED));
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        // If you save a non date value, you get null
        meta.set(TikaCoreProperties.CREATED, "INVALID");
        assertEquals("INVALID", meta.get(TikaCoreProperties.CREATED));
        assertEquals(null, meta.getDate(TikaCoreProperties.CREATED));

        // If you try to retrieve a non simple date value, you get null
        meta.set(TikaCoreProperties.CREATED, new Date(1000));
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());
        assertEquals(null, meta.getInt(Metadata.BITS_PER_SAMPLE));
        assertEquals(null, meta.getInt(TikaCoreProperties.CREATED));

        // Our format doesn't include milliseconds
        // This means things get rounded 
        meta.set(TikaCoreProperties.CREATED, new Date(1050));
        assertEquals("1970-01-01T00:00:01Z", meta.get(TikaCoreProperties.CREATED));
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        // We can accept a number of different ISO-8601 variants
        meta.set(TikaCoreProperties.CREATED, "1970-01-01T00:00:01Z");
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        meta.set(TikaCoreProperties.CREATED, "1970-01-01 00:00:01Z");
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        meta.set(TikaCoreProperties.CREATED, "1970-01-01T01:00:01+01:00");
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        meta.set(TikaCoreProperties.CREATED, "1970-01-01 01:00:01+01:00");
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        meta.set(TikaCoreProperties.CREATED, "1970-01-01T12:00:01+12:00");
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        meta.set(TikaCoreProperties.CREATED, "1969-12-31T12:00:01-12:00");
        assertEquals(1000, meta.getDate(TikaCoreProperties.CREATED).getTime());

        // Dates without times, come in at midday UTC
        meta.set(TikaCoreProperties.CREATED, "1970-01-01");
        assertEquals(12 * hour, meta.getDate(TikaCoreProperties.CREATED).getTime());

        meta.set(TikaCoreProperties.CREATED, "1970:01:01");
        assertEquals(12 * hour, meta.getDate(TikaCoreProperties.CREATED).getTime());
    }
Tests for getting and setting date
based properties
tika-core/src/test/java/org/apache/tika/metadata/TestMetadata.java