Home page logo
/
Zenmap screenshot
Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News
Example Nmap output

Library datetime

Functions for dealing with dates and timestamps

Author:

  • Daniel Miller

Copyright© Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/datetime.lua

Functions

date_to_timestamp (date, offset)

Convert a date table into an integer timestamp.

format_difftime (t2, t1)

Format the difference between times t2 and t1 into a string

format_time (interval, unit)

Format a time interval into a string

format_timestamp (t, offset)

Format a date and time (and optional time zone) for structured output.

record_skew (host, timestamp, received)

Record a time difference between the scanner and the target



Functions

date_to_timestamp (date, offset)

Convert a date table into an integer timestamp.

Unlike os.time, this does not assume that the date table represents a local time. Rather, it takes an optional offset number of seconds representing the time zone, and returns the timestamp that would result using that time zone as local time. If the offset is omitted or 0, the date table is interpreted as a UTC date. For example, 4:00 UTC is the same as 5:00 UTC+1:

date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0})          --> 14400
date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}, 0)       --> 14400
date_to_timestamp({year=1970,month=1,day=1,hour=5,min=0,sec=0}, 1*60*60) --> 14400
And 4:00 UTC+1 is an earlier time:
date_to_timestamp({year=1970,month=1,day=1,hour=4,min=0,sec=0}, 1*60*60) --> 10800

Parameters

  • date:
  • offset:
format_difftime (t2, t1)

Format the difference between times t2 and t1 into a string

String is in one of the forms (signs may vary):

  • 0s
  • -4s
  • +2m38s
  • -9h12m34s
  • +5d17h05m06s
  • -2y177d10h13m20s
The string shows t2 relative to t1; i.e., the calculation is t2 minus t1.

Parameters

  • t2:
  • t1:
format_time (interval, unit)

Format a time interval into a string

String is in the same format as format_difftime

Parameters

  • interval: A time interval
  • unit: The time unit division as a number. If interval is in milliseconds, this is 1000 for instance. Default: 1 (seconds)

Return value:

The time interval in string format
format_timestamp (t, offset)

Format a date and time (and optional time zone) for structured output.

Formatting is done according to RFC 3339 (a profile of ISO 8601), except that a time zone may be omitted to signify an unspecified local time zone. Time zones are given as an integer number of seconds from UTC. Use 0 to mark UTC itself. Formatted strings with a time zone look like this:

format_timestamp(os.time(), 0)       --> "2012-09-07T23:37:42+00:00"
format_timestamp(os.time(), 2*60*60) --> "2012-09-07T23:37:42+02:00"
Without a time zone they look like this:
format_timestamp(os.time())          --> "2012-09-07T23:37:42"

This function should be used for all dates emitted as part of NSE structured output.

Parameters

  • t:
  • offset:
record_skew (host, timestamp, received)

Record a time difference between the scanner and the target

The skew will be recorded in the host's registry for later retrieval and analysis. Adjusts for network distance by subtracting half the smoothed round-trip time.

Parameters

  • host: The host being scanned
  • timestamp: The target timestamp, in seconds.
  • received: The local time the stamp was received, in seconds.

Nmap Site Navigation

Intro Reference Guide Book Install Guide
Download Changelog Zenmap GUI Docs
Bug Reports OS Detection Propaganda Related Projects
In the Movies In the News
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]