linux GetLocalTime

typedef struct
{
  int wSecond; /* Seconds. [0-60] (1 leap second) */
  int wMinute; /* Minutes. [0-59] */
  int wHour; /* Hours. [0-23] */
  int wDay;    /* Day. [1-31] */
  int wMonth; /* Month. [0-11] */
  int wYear; /* Year - 1900.  */
  int wDayOfWeek; /* Day of week. [0-6] */
  int tm_yday; /* Days in year.[0-365] */
  int tm_isdst; /* DST. [-1/0/1]*/
#ifdef __USE_BSD
  long int tm_gmtoff; /* Seconds east of UTC.  */
  __const char *tm_zone; /* Timezone abbreviation.  */
#else
  long int __tm_gmtoff; /* Seconds east of UTC.  */
  __const char *__tm_zone; /* Timezone abbreviation.  */
#endif
}SYSTEMTIME;

void GetLocalTime(SYSTEMTIME *st)
{
    if(st)
    {
        struct tm *pst = NULL;
        time_t t = time(NULL);
        pst = localtime(&t);
        memcpy(st,pst,sizeof(SYSTEMTIME));
        st->wYear += 1900;
    }
}

#include <time.h>
int main()
{
    char buf[32] = {0};
    struct tm* ptm = NULL;
    time_t t = time(NULL);
    ptm = localtime(&t);
    strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",ptm);
    cout<<buf<<endl;
    return -1;
}
/*
%y   Year without century, as a decimal number (00-99).
%Y   Year with century, as a decimal number.
%m  Month as a decimal number (01-12).
%M  Minute as a decimal number (00-59).
%d   Day of the month as a decimal number (01-31).
%H  Hour (24-hour clock) as a decimal number (00-23).
%S  Second as a decimal number (00-59).
*/

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值