C++ 获取时间戳:下周一、月初、月中、月末

C++ 获取时间戳:下周一、月初、月中、月末

在一次开发过程中需要利用当前时间获取下周一、这个个月月中、这个月月末和下个月月初的时间戳,在此做一个总结。

#include <stdio.h>
#include <iostream>
#include <unistd.h>
#include <time.h>

#define ONE_DAY (86400)

using namespace std;

int GetWeek(long now_timestamp) {
    struct tm gmtm;
    gmtime_r(&now_timestamp, &gmtm);
    int day_of_week = gmtm.tm_wday;
    return day_of_week == 0?7:day_of_week;
}

int GetDay(long now_timestamp) {
    struct tm gmtm;
    gmtime_r(&now_timestamp, &gmtm);
    int day_of_month = gmtm.tm_mday;
    return day_of_month;
}

int GetYears(long now_timestamp) {
    struct tm gmtm;
    gmtime_r(&now_timestamp, &gmtm);
    int years = gmtm.tm_year;
    return years;
}

int GetMonth(long now_timestamp) {
    struct tm gmtm;
    gmtime_r(&now_timestamp, &gmtm);
    int month = gmtm.tm_mon;
    return month;
}

int GetDaysInMonth(long now_timestamp)
{
    int now_years = GetYears(now_timestamp
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值