Encoding and decoding for datetimes.