Quantcast
Viewing all articles
Browse latest Browse all 37

Answer by mwfearnley for Porting Linux date parsing to FreeBSD

You can parse a date in a specific format in FreeBSD using:

date -j  -f "$input_fmt"  "$input_date"  +"$output_fmt"

According to the date manpage:

-j

Do not try to set the date. This allows you to use the -f flag in addition to the + option to convert one date format to another. Note that any date or time components unspecified by the -f format string take their values from the current time.

-f input_fmt

Use input_fmt as the format string to parse the new_date provided rather than using the default [[[[[cc]yy]mm]dd]HH]MM[.SS] format. Parsing is done using strptime(3).

More info about the format flags is in the strftime manpage.

For example:

date -j  -f "%d %b %Y"  "18 Feb 2025"  +"%Y-%m-%d"2025-02-18

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>