bash date format
Bash Date
To format Bash Date to a required one, bash shell provides date command along with many format options.
Bash Date Command
Following is the syntax of date command
|
$ date
|
Format Bash Date with Options
As already said, you can format the Bash Date. And the format you wish may contain spaces as well.
Date command accepts options if provided any
|
$ date +<format-option><format-option>
|
To format date with spaces, use the syntax
|
$ date '+<format-option><format-option> <format-option>'
|
List of Bash Date Formatting Options
Following are the list of available options for date command :
| Format option | Part of Date | Desciption | Example Output |
|---|---|---|---|
| date +%a | Weekday | Name of weekday in short (like Sun, Mon, Tue, Wed, Thu, Fri, Sat) | Mon |
| date +%A | Weekday | Name of weekday in full (like Sunday, Monday, Tuesday) | Monday |
| date +%b | Month | Name of Month in short (like Jan, Feb, Mar ) | Jan |
| date +%B | Month | Month name in full short (like January, February) | January |
| date +%d | Day | Day of month (e.g., 01) | 04 |
| date +%D | MM/DD/YY | Current Date; shown in MM/DD/YY | 02/18/18 |
| date +%F | YYYY-MM-DD | Date; shown in YYYY-MM-DD | 2018-01-19 |
| date +%H | Hour | Hour in 24-hour clock format | 18 |
| date +%I | Hour | Hour in 12-hour clock format | 10 |
| date +%j | Day | Day of year (001..366) | 152 |
| date +%m | Month | Number of month (01..12) (01 is January) | 05 |
| date +%M | Minutes | Minutes (00..59) | 52 |
| date +%S | Seconds | Seconds (00..59) | 18 |
| date +%N | Nanoseconds | Nanoseconds (000000000..999999999) | 300231695 |
| date +%T | HH:MM:SS | Time as HH:MM:SS (Hours in 24 Format) | 18:55:42 |
| date +%u | Day of Week | Day of week (1..7); 1 is Monday | 7 |
| date +%U | Week | Displays week number of year, with Sunday as first day of week (00..53) | 23 |
| date +%Y | Year | Displays full year i.e. YYYY | 2018 |
| date +%Z | Timezone | Time zone abbreviation (Ex: IST, GMT) | IST |
You may use any of the above-mentioned format options (first column) for the date command in the aforementioned syntax.
Examples
Bash Date Format MM-DD-YYYY
To format date in MM-DD-YYYY format, use the command date +%m-%d-%Y .
|
#!/bin/bash
d=`date +%m-%d-%Y`
echo $d # 12-30-2017
|
Please observe the upper and lower case letters : %m for month, %d for day and %Y for year. %M would mean minutes.
Bash Date Format MM-YYYY
To format date in MM-YYYY format, use the command date +%m-%Y .
|
#!/bin/bash
d=`date +%m-%Y`
echo $d # 12-2017
|
Bash Date Format: Weekday DD-Month, YYYY
To format date in MM-DD-YYYY format, use the command date +%m-%d-%Y .
|
#!/bin/bash
d=`date '+%A %d-%B, %Y'`
echo $d # Saturday 30-December, 2017
|
bash date format的更多相关文章
- javascript Date format(js日期格式化) (转)
方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) ...
- [转]javascript Date format(js日期格式化)
方法一:这个很不错,好像是 csdn 的 Meizz 写的: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) ...
- javascript Date format(js日期格式化)
这个用这比较爽,记录一下// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年( ...
- [荐]javascript Date format(js日期格式化)
cnblog:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html 方法一: // 对Date的扩展,将 Date ...
- JS Date.Format
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- Javascript Date Format
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- Date Format, 时间戳格式化
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- js new Date().Format
/** * * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符 * 年(y)可以用 1-4 ...
- GG同步sqlserver报错一个案例 Invalid date format
在里面Oracle表同步sqlserver时间,在sqlserver当应用程序数据的结束.您可能会遇到这个错误. 2014-05-17 17:20:24 WARNING OGG-01154 SQL e ...
随机推荐
- docker初学
Docker基础知识 1. Docker基础知识点 1.1 什么是Docker Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.(集装箱原理) 1.2 什 ...
- java 抽象的概念 抽象类的使用
package java10; /* 抽象方法:就是加上abstract关键字,然后去掉大括号,直接分号结束 抽象类:抽象方法所在的类,必须是抽象类才行.在class之前写上abstract即可 如何 ...
- 学会如何使用shiro
摘:https://www.cnblogs.com/learnhow/p/5694876.html 一.架构 要学习如何使用Shiro必须先从它的架构谈起,作为一款安全框架Shiro的设计相当精妙.S ...
- tomcat启动一闪而过解决办法报错The CATALINA_HOME environment variable is not defined correctly
解决办法: Tomcat无论在windows上还是Linux上只需要吧安装包传上去解压就行,不需要配置环境变量,吧之前有可能别人别配置的环境变量统一删掉即可(网上一大堆说需要配置的都是胡说八道).把以 ...
- canvas 星星闪烁的效果
代码实例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- mybatis整合redis二级缓存
mybatis默认开启了二级缓存功能,在mybatis主配置文件中,将cacheEnabled设置成false,则会关闭二级缓存功能 <settings> <!--二级缓存默认开启, ...
- StrictMode 严格模式
StrictMode: 帮助程序员避免在主线程上执行耗时操作: 启动级别: 1. 启动线程级别: setThreadPolicy() 2. 启动应用级别 : setVmPolicy() —— 对 ...
- delphi 解决RichViewEdit乱码问题
⑴ 设置RichViewEdit下面的几个属性: ① RTFReaderProperties → ParaStyleMode → rvrsAddIfNeeded ② RTFReaderProperti ...
- PWN入门的入门——工具安装
安装pwntool: 命令行运行: pip install pwntools python import pwn pwn.asm("xor eax,eax") 出现'1\xc0' ...
- element table 通过selection-change选中的索引删除
<el-table :row-class-name="tableRowClassName" @selection-change="handleSelectionCh ...