zoukankan      html  css  js  c++  java
  • lua 获取前一天的日期的函数

    获得前一天的日期的函数

     1 function day_step(old_day,step) 
     2    local y,m,d
     3    if("0" ~= string.sub(old_day,6,6)) then
     4       m=string.sub(old_day,6,7)
     5    else
     6       m=string.sub(old_day,7,7)
     7    end
     8 
     9    if("0" ~= string.sub(old_day,9,9)) then
    10       d=string.sub(old_day,9,10)
    11    else
    12       d=string.sub(old_day,10,10)
    13    end
    14 
    15    y=string.sub(old_day,0,4)
    16    
    17    local old_time=os.time{year=y,month=m,day=d}
    18    local new_time=old_time+86400*step
    19 
    20    local new_day=os.date("*t",new_time)
    21    local res=""
    22 
    23    if(tonumber(new_day.day)<10 and tonumber(new_day.month)<10)then
    24       res=new_day.year.."-".."0"..new_day.month.."-".."0"..new_day.day
    25    elseif tonumber(new_day.month)<10 then
    26       res=new_day.year.."-".."0"..new_day.month.."-"..new_day.day
    27    
    28    elseif tonumber(new_day.day)<10 then
    29       res=new_day.year.."-"..new_day.month.."-".."0"..new_day.day
    30    else
    31       res=new_day.year.."-"..new_day.month.."-"..new_day.day
    32    end
    33    return res
    34 end
    day_step("2013-06-04",-1) -输出-> "2013-06-03"
  • 相关阅读:
    java基础5 (一维)数组和二维数组
    Java 内部类
    Java 抽象类和接口
    Java 多态
    Java 继承
    Java 包(package)
    Java String类和StringBuffer类
    Java 数组
    Java 封装与类
    Java 概述和编程基础
  • 原文地址:https://www.cnblogs.com/liqiu/p/3123702.html
Copyright © 2011-2022 走看看