Procedures for Formatting Dates and Times

Table of Contents

  1. Introduction
  2. Formatting Julian Day Numbers (JDNs)
  3. Formatting Modified Julian Dates (MJDs)

Introduction

Date/time concepts are introduced in Functions for Formatting Dates and Times. The file date.tcl defines the two formatting procedures format_jdn and format_mjd, as well as these functions.

These two formatting procedures use the standard Tcl clock command. The range of dates which clock can handle depends on the platform. The current (8.4.7) Windows version uses a 32-bit signed integer offset (seconds) from 1970-01-01, allowing dates from 1901-12-13 to 2038-01-19.

Formatting Julian Day Numbers (JDNs)

The command
format_jdn jdn [format]
formats the Julian Day Number jdn, one value per line.

jdn can be any NAP expression.

format is that required for the clock command. The default format is "%Y-%m-%d", which produces a standard ISO 8601 date in the form "yyyy-mm-dd".

Examples

% format_jdn 2453305
2004-10-26
% format_jdn 2453305 "%A %B %d, %Y"
Tuesday October 26, 2004
% format_jdn "{0 7} + date2jdn{2004 10 22}"
2004-10-22
2004-10-29
% format_jdn "{0 7} + date2jdn{2004 10 22}" "%y %m %d"
04 10 22
04 10 29

Formatting Modified Julian Dates (MJDs)

The command
format_mjd mjd [format]
formats the Modified Julian Date mjd, one value per line.

mjd can be any NAP expression. This is rounded to the nearest second.

format is that required for the clock command. The default format is "%Y-%m-%dT%H:%M:%S", which produces a standard ISO 8601 date/time in the form "yyyy-mm-ddTHH:MM:SS".

Examples

% format_mjd 49797.75
1995-03-21T18:00:00
% format_mjd 49797.75 "%I %p on %A %d %B, %Y."
06 PM on Tuesday 21 March, 1995.
% format_mjd "{0 0.5} + dateTime2mjd{2004 10 22 16 30 59}"
2004-10-22T16:30:59
2004-10-23T04:30:59
% format_mjd "{0 0.5} + dateTime2mjd{2004 10 22 16 30 59}" "%y%m%d %H%M"
041022 1630
041023 0430

Author: Harvey Davies       © 2002, CSIRO Australia.       Legal Notice and Disclaimer
CVS Version Details: $Id: date_proc.html,v 1.2 2004/10/26 01:48:55 dav480 Exp $