SooSeok Park
SooSeok Park

Reputation: 9

How to represent datetime format using EBNF

I want to know about how to represent the 'datetime' format such as "yyyy-MM-dd hh:mm" using EBNF.

Upvotes: 0

Views: 251

Answers (1)

Robin Keskisarkka
Robin Keskisarkka

Reputation: 896

One possible way of formulating this using EBNF is shown below. The expression parses only legal years, months and timestamps. However, it allows any month to have up to 31 days.

Timestamp = [ "-" ] Year "-" Month "-" Day " " Time ;
Year = Digit Digit Digit Digit ;
Month = "0" Digit | "1" "0".."2" ;
Day = "0".."2" Digit | "3" "0".."1" ;
Time = Hour ":" Minute ;
Hour = "0".."1" Digit | "2" "0".."3" ;
Minute = "0".."5" Digit ;
Digit = "0".."9" ;

Upvotes: 0

Related Questions