标签:linux
[Author]: kwu
在linux中日期格式化固定为8位:2015-01-01
如实现 2015-1-1 需要进行字符串处理
#!/bin/sh # upload logs to hdfs yesterday2="2015-01-08" echo ${yesterday2} first=${yesterday2:5:1} second=${yesterday2:8:1} echo ${first} echo ${second} res=$yesterday2 echo ${res} if [ $first -eq 0 ] && [ $second -eq 0 ] then res=${yesterday2:0:5}${yesterday2:6} res=${res:0:7}${res:8} elif [ $first -eq 0 ] then res=${yesterday2:0:5}${yesterday2:6} elif [ $second -eq 0 ] then res=${yesterday2:0:8}${yesterday2:9} fi echo ${res}
2015-1-8
标签:linux
原文地址:http://blog.csdn.net/bdchome/article/details/45740365