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 ...
随机推荐
- 二、Angular项目创建、安装、启动
1.项目创建,进入预先存放项目的路径,命令行执行 ng new ProjectName 创建成功后的项目 2.项目安装,进行项目中执行命令 npm install 3. 项目运行,执行命令 ng s ...
- Sass-@for
在制作网格系统的时候,大家应该对 .col1~.col12 这样的印象较深.在 CSS 中你需要一个一个去书写,但在 Sass 中,可以使用 @for 循环来完成.在 Sass 的 @for 循环中有 ...
- chrome插件研发手册
chrome插件研发手册 一:需求前景 对于研发的小伙伴来说,总会遇到这样的需求,想要通过代码操作已有网站的行为动作,如:自动填充表格内容(表单内容太多,想一键将表单内容填充):自动登录网站(网站登录 ...
- bzoj5049 [Lydsy1709月赛]导航系统 双向bfs
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5049 题解 题面里面满眼的随机.既然数据完全随机,那就是在锻炼选手的乱搞能力啊. 根据一个常用 ...
- 09.事务管理、整合jpa、整合mybatis
事务管理 spring-boot-starter-jdbc会自动默认注入DataSourceTransactionManager spring-boot-starter-data-jpa会自动默认注入 ...
- gensim Load embeddings
gensim package from gensim.models.keyedvectors import KeyedVectors twitter_embedding_path = 'twitter ...
- 阿里云HPC助力新制造 | 上汽仿真计算云SSCC
随着上汽集团与阿里云的合作开展,阿里云各项技术逐步深入到上汽汽车研发领域的核心业务实现落地.其中上海汽车集团股份有限公司乘用车分公司(以下简称上汽乘用车)与阿里云共建的仿真计算混合云就是新制造产业升级 ...
- 安装并配置前端自动化工具-gulp
由于现在前端自动化已经很有必要了,所以我今天死皮烂脸的找了2位前端大咖帮助我安装和配置gulp,讲真,这一步步弄下来直到安装配置成功,到现在还是迷迷糊糊,不过我还是把这些步骤给记录下来,以防下次不记得 ...
- create-react-app 配置 修改
1.端口号修改:https://www.jianshu.com/p/80a7603dda70(亲测有效) 在 根据 package.json 的启动,node_modules文件夹里面搜索reac ...
- 第二章(1.3)Python基础知识(输入输出)
一.?输出 用print加上字符串,就可以向屏幕上输出指定的文字 print?'hello, world' print也可以打印整数. >>> print?300 二.?输入 Pyt ...