@@ -95,7 +95,8 @@ static inline int date_month(FAR const char *abbrev)
95
95
96
96
#ifndef CONFIG_NSH_DISABLE_DATE
97
97
static inline int date_showtime (FAR struct nsh_vtbl_s * vtbl ,
98
- FAR const char * name , bool utc )
98
+ FAR const char * name , bool utc ,
99
+ FAR const char * format )
99
100
{
100
101
struct timespec ts ;
101
102
struct tm tm ;
@@ -132,7 +133,7 @@ static inline int date_showtime(FAR struct nsh_vtbl_s *vtbl,
132
133
133
134
/* Show the current time in the requested format */
134
135
135
- ret = strftime (timbuf , MAX_TIME_STRING , "%a, %b %d %H:%M:%S %Y" , & tm );
136
+ ret = strftime (timbuf , MAX_TIME_STRING , format , & tm );
136
137
if (ret < 0 )
137
138
{
138
139
nsh_error (vtbl , g_fmtcmdfailed , name , "strftime" , NSH_ERRNO );
@@ -367,6 +368,7 @@ int cmd_time(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
367
368
int cmd_date (FAR struct nsh_vtbl_s * vtbl , int argc , FAR char * * argv )
368
369
{
369
370
FAR char * newtime = NULL ;
371
+ FAR const char * format = "%a, %b %d %H:%M:%S %Y" ;
370
372
FAR const char * errfmt ;
371
373
bool utc = false;
372
374
int option ;
@@ -395,11 +397,21 @@ int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
395
397
}
396
398
}
397
399
398
- /* optind < argc-1 means that there are additional, unexpected arguments on
400
+ argc -= optind ;
401
+
402
+ /* Display the time according to the format we set */
403
+
404
+ if (argv [optind ] && * argv [optind ] == '+' )
405
+ {
406
+ format = argv [optind ] + 1 ;
407
+ argc -- ;
408
+ }
409
+
410
+ /* argc > 0 means that there are additional, unexpected arguments on
399
411
* th command-line
400
412
*/
401
413
402
- if (optind < argc )
414
+ if (argc > 0 )
403
415
{
404
416
errfmt = g_fmttoomanyargs ;
405
417
goto errout ;
@@ -413,7 +425,7 @@ int cmd_date(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
413
425
}
414
426
else
415
427
{
416
- ret = date_showtime (vtbl , argv [0 ], utc );
428
+ ret = date_showtime (vtbl , argv [0 ], utc , format );
417
429
}
418
430
419
431
return ret ;
0 commit comments