How to validate that time format in Java is as expected
<p>In my REST API Controller with @PathVariable("timestamp) I have to validate that timestamp format is complaint with ISO 8601 standard:  eg. 2016-12-02T18:25:43.511Z.</p>

<pre><code>@RequestMapping("/v3/testMe/{timestamp}")
public class TestController {

    private static final String HARDCODED_TEST_VALUE = "{\n\t\"X\": \"01\",\n\t\"Y\": \"0.2\"\n}";

    @ApiOperation(nickname = "getTestMe", value = "Return TestMe value", httpMethod = "GET",
            authorizations = {@Authorization(value = OAUTH2,
                    scopes = {@AuthorizationScope(scope = DEFAULT_SCOPE, description = SCOPE_DESCRIPTION)})})
    @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String getTestMe(@PathVariable("timestamp") String timestamp) {

        if (timestamp != null)        {
            return HARDCODED_TEST_VALUE;
        }

        throw new ResourceNotFoundException("wrong timestamp format");
    }
}
</code></pre>

<p>The way of how I would like to achieve it is similiar to above if-else statement that check whether timestamp is null or not - so analogically I would like to add similiar if-else to validate format of timestamp and return body if so or 404 error code if it's not.</p>

<p>Any idea what I could use to do that and please give me ready example ? I've tried simple validation with regex but is not convenient and unfortunately didn't work anyway ... </p>