以下awk代码按预期工作。仅从日期和时间提取日期
像2012-03-10〜12:59:41这样的日期四舍五入到最接近的五分钟,例如, 2012-03-10〜12:55:00
我该如何改变它,以便我可以像20120310(没有短划线)那样得到年中一天?
BEGIN {
# all fields are separated by^
FS = "^";
}
{
# $7 is the date and time in the form yyyy-mm-dd hh:mm:ss.
# Split at colons to get hours minutes and seconds into a[1]
# through a[3]. Round minutes to nearest 5.
split($7, a, ":");
a[2] = int(a[2]/5) * 5;
# print first, second and forth field, then rounded time.
printf "set %s:%s:%s %s:%02d:00\\r\\n\n", $1, $2, $4, a[1], a[2];
}
分裂($ 7, “ - ”); #正在工作,但03月因为我使用[2] = int(a [2])而转换为3;我如何转换为文本?这a [2] = var(a [2]);不起作用。 – shantanuo 2012-03-18 11:17:21