• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Linux-wang
博客园    首页    新随笔    联系   管理    订阅  订阅
获取次日日期(主要两种方法)
1.直接调用shell脚本
afterdata=$(date -d +1day "+%Y%m%d")
 
 
 
2.C语言获取后几天time
#include <stdio.h>
#include <time.h>
#include <string.h>
int main(int argc,char const *argv[])
{
    char yestDt[9];
    time_t now = time(NULL);//获取1970.1.1到目前经过的秒数
    struct tm *ts = localtime(&now);//获取本地时间(与时区相关)
    ts->tm_mday++;
    mktime(ts);//将ts转换为经过的秒数
    strftime(yestDt,sizeof(yestDt),"%Y%m%d",ts); //输出格式加个%T等同于%H%M%S
    printf("Yesterday is \"%s\"\n",yestDt);
    return 0;
}

 

posted on 2017-12-29 09:32  SmallMosquito  阅读(496)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3