mysql 截取某一个时间(datetime类型)的日期:
方法1:select date(row_name) from table_name where row = row1;
方法2:select left(row_name, 10) from table_name where row = row1;
方法3:select cast(row_name as char[10]) from table_name where row = row1;
取得某个日期的time_t数值:select unix_timestamp(date(row_name)) from table_name where row = row1;
以time_t为参数取得某个时间
time_t 是'1970-01-01 00:00:00'以来的秒数
select '1970-01-01 00:00:00'+ INTERVAL time_t_num SECOND ;
取得当前日期:select curdate();
取得当前时间:select now();
将日期转化为短日期格式
SELECT REPLACE(date(row_name), '-0', '-');
linux下c++常用时间处理函数
clock()用来程序计时
例如: 以下摘自
#include “stdio.h”
#include “stdlib.h”
#include “time.h”
int main( void )
{
long i = 10000000L;
clock_t start, finish;
double duration;
/* 测量一个事件持续的时间*/
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- ) ;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%f seconds\n", duration );
system("pause");
}
示例出处:DIY部落(http://www.diybl.com/course/3_program/vc/vc_js/20090307/159296.html)
time_t类型
time_t t = time(NULL);
time_t转成tm类型
struct tm* t_tm = localtime(time(NULL));
time_t转成字符串格式
struct tm* tm_ago = localtime(&t);
sprintf(date_days_ago, "%04d-%02d-%02d", 1900+tm_ago->tm_year,
tm_ago->tm_mon+1, tm_ago->tm_mday);
time_t t_now = time(NULL); //seconds since 1970-01-01
struct