datetime
char datetime[100];
time_t now;
struct tm *tm_now;
time(&now);
tm_now = localtime(&now);
strftime(datetime, 100, “%Y%m%d%H%M%S”, tm_now);
PHP:
//将20161204002053转换为2016-12-04 00:20:53,以用于sql查询
$time = '20161204002053';
$t1 = strtotime($time);
$time = date("Y-m-d H:i:s", $t1);
JAVA:
///取当前时间
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());
String strNow = formatter.format(curDate);
//获取一周前时间
Calendar cal = Calendar.getInstance();//使用默认时区和语言环境获得一个日历。
cal.add(Calendar.DAY_OF_MONTH, -7);//取当前日期的前一天.
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd EE hh:mm:ss");
String strPre7Days = df.format(cal.getTime());
QT
获取当前时间:
QDateTime now = QDateTime::currentDateTime();
字符串转时间:
QDateTime last = QDateTime::fromString(last_active, "yyyy-MM-dd hh:mm:ss");
时间转字符串:
QString strTimeLine = now.toString("yyyy-MM-dd hh:mm:ss");
BASH
DATE=`date "+%Y-%m-%d %H:%M:%S"`
echo $DATE