Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Bash: Display Date and Time In a Specific Format

    Bash: Display Date and Time In a Specific Format

    By RahulDecember 19, 20222 Mins Read

    To display the current date and time in a specific format in Bash, you can use the date command. The date command allows you to specify a format string that determines the format in which the date and time are displayed.

    Advertisement

    For example, to display the current date and time in the format “YYYY-MM-DD HH:MM:SS”, you can use the following command:

    date +"%Y-%m-%d %H:%M:%S" 
    

    Here are some common format specifiers you can use in the format string:

    • %Y: Year with century as a decimal number (2022).
    • %m: Month as a decimal number (01-12).
    • %d: Day of the month as a decimal number (01-31).
    • %H: Hour in 24-hour format (00-23).
    • %M: Minute as a decimal number (00-59).
    • %S: Second as a decimal number (00-59).

    Some other useful specifiers, you should also know:

    • %a: abbreviated weekday name (e.g., Sun).
    • %A: full weekday name (e.g., Sunday).
    • %b: abbreviated month name (e.g., Jan).
    • %B: locale’s full month name (e.g., January).
    • %D: date; same as %m/%d/%y .
    • %I: hour (01..12).
    • %p: locale’s equivalent of either AM or PM; blank if not known.
    • %U: Week number of year (00..53).

    Let’s take another example, to display the current date in the format “DD/MM/YYYY”, you can use the following command:

    date +"%d/%m/%Y" 
    

    You can also use other format specifiers to display the date and time in different ways. For example, to display the current month and year in the format “Month Year”, you can use the following command:

    date +"%B %Y" 
    

    The %B represents the full name of the month.

    You can find a full list of format specifiers on the `date` command’s man page. To view the man page, type `man date` at the command prompt.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Setting Up Permissions in Home Directory on Linux

    Configuring Apache Userdir on Ubuntu and Debian: A Simplified Guide

    How to Permanently Disable Swap Partition in Linux

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Python Function with Parameters, Return and Data Types
    • free Command in Linux (Check Memory Uses)
    • Git Rebase: A Practical Guide
    • How to move the complete Git repository
    • Handling Special Characters in Shell Scripts
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.