ParseTime - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


StringTools

  

ParseTime

  

parse a string containing date and time information

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

ParseTime( fmt, str )

Parameters

fmt

-

string; format specifier

str

-

string; string to be parsed

Description

• 

The ParseTime( fmt,str ) command parses the string str, assumed to contain date and time data, according to the parsing specification given by the format string fmt.

• 

The time format string is a Maple string that can contain time and date format conversion specifiers, introduced by a % character. This works in a manner similar to the conversion specifiers used in printf or sscanf, but the defined conversion specifiers are different. The format conversion specifiers are a subset of those supported by the FormatTime procedure.

• 

The string str to be parsed is assumed to contain date and time information in the format described by fmt. Characters in fmt and str are matched, with the format conversion specifiers in fmt acting as placeholders or wildcards for the actual date and time data present in the string str. If the two strings match, then the date and time data extracted from str are returned in the form of a record, described below. If the strings fail to match, then an exception is raised.

• 

The following table lists the known conversion specifiers and their meanings.

%%

the string "%"

%a

abbreviated weekday name

%A

the full weekday name

%b

abbreviated month name

%B

full month name

%c

a standard date and time representation

%C

the century number (the year divided by 100 and truncated to an integer in the range 01 - 99)

%d

a two-digit day of the month number

%D

the date in the form MM/DD/YY.

%e

the day of the month (01-31).

%H

the hour in a 24-hour clock (00-23).

%I

the hour in a 12-hour clock (01-12).

%j

day number (01-366).

%k

the hour in a 24-hour clock ( 0-23).

%l

the hour in a 12-hour clock ( 1-12).

%m

the month number (01-12).

%M

the minute after the hour (00-59).

%n

a newline character

%p

a.m. or p.m.

%r

time representation for a 12-hour clock (using %p).

%R

the same as %H:%M.

%S

seconds after the minute (00-61)

%t

a tab character

%T

same as %H:%M:%S.

%u

weekday as a decimal number (1-7; 1 = Sunday).

%U

week number of the year (00-53); Sunday is the first day of week 1.

%V

The ISO 8601 week number (01-53).

%w

weekday (0-6); 0 = Sunday.

%x

a standard date representation.

%X

a standard time representation.

%y

year within the century (00-99)

%Y

year including the century (YYYY)

%Z

time zone name or abbreviation, if available.

• 

The record returned by ParseTime contains slots with the following meanings and ranges of values.

second

seconds after the minute

0-61

minute

minutes after the hour

0-59

hour

hour of the day

0-23

monthDay

day of the month

1-32

month

month of the year

1-12

year

the year

0-9999

weekDay

day of the week

1-7

yearDay

day of the year

1-366

dst?

if known, whether daylight savings time is in effect

true, false

• 

Not all slots of this record will be updated for a given pair of inputs. Only those slots whose values can be determined from the given data will have meaningful values.

• 

All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

withStringTools:

dtParseTime%Y-%m-%d,2002-11-05:

dt:-year,dt:-month,dt:-monthDay

2002,11,5

(1)

dtParseTime%Y-%m-%d,1964-01-14:

dt:-year,dt:-month,dt:-monthDay

1964,1,14

(2)

dtParseTimeWelcome to the %Cth Century!,Welcome to the 19th Century!:

dt:-year

1900

(3)

sFormatTime%c

sFri Mar 01 00:25:22 2024

(4)

dtParseTime%c,s

dtRecordcalendar=Gregorian,second=22,minute=25,hour=0,monthDay=1,month=3,year=2024,weekDay=6,weekDayName=Friday,yearDay=61,dst?=false

(5)

dt:-second,dt:-minute,dt:-hour

22,25,0

(6)

dt:-monthDay,dt:-month,dt:-year

1,3,2024

(7)

dt:-weekDay,dt:-yearDay

6,61

(8)

ParseTime%Y-%m-%d,1752-09-02:-weekDay

4

(9)

ParseTime%Y-%m-%d,1752-09-14:-weekDay

5

(10)

See Also

FormatMessage

FormatTime

iolib

printf

sscanf

string

StringTools