CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

有没有获得当前月份上个月的函数???

楼主rst_2828(海岛管理员)2003-12-18 11:51:42 在 Delphi / VCL组件开发及应用 提问

如当前月份为12月,要获得11月。 问题点数:0、回复次数:15Top

1 楼outer2000(天外流星)回复于 2003-12-18 11:58:15 得分 0

Returns   a   date   shifted   by   a   specified   number   of   months.  
   
  Unit  
   
  SysUtils  
   
  Category  
   
  datetime   routines  
   
  Delphi   syntax:  
   
  function   IncMonth(const   Date:   TDateTime;   NumberOfMonths:   Integer   =   1):   TDateTime;  
   
  C++   syntax:  
   
  extern   PACKAGE   System::TDateTime   __fastcall   IncMonth(const   System::TDateTime   Date,   int   NumberOfMonths   =   1);  
   
  Description  
   
  IncMonth   returns   the   value   of   the   Date   parameter,   incremented   by   NumberOfMonths   months.     NumberOfMonths   can   be   negative,   to   return   a   date   N   months   previous.  
   
  If   the   input   day   of   month   is   greater   than   the   last   day   of   the   resulting   month,   the   day   is   set   to   the   last   day   of   the   resulting   month.     The   time   of   day   specified   by   the   Date   parameter   is   copied   to   the   result.Top

2 楼8009000077()回复于 2003-12-18 12:00:36 得分 0

incMonth()Top

3 楼angle097113(深思不解)回复于 2003-12-18 12:08:07 得分 0

我一般是获得当前的月份   然后减1实现得Top

4 楼aiirii(ari-http://spaces.msn.com/members/aiirii/)回复于 2003-12-18 12:08:07 得分 0

uses   DateUtils  
   
  MonthOf(now)   -   1Top

5 楼gencan(无敌)回复于 2003-12-18 12:27:30 得分 0

MonthOf(now)   -   1  
  Top

6 楼nxfbccu(杀缺衣)回复于 2003-12-18 12:34:36 得分 0

uses   DateUtils  
   
  MonthOf(now)   -   1  
  Top

7 楼aiirii(ari-http://spaces.msn.com/members/aiirii/)回复于 2003-12-18 12:37:20 得分 0

i   :=   MonthOf(now)   -   1;  
  if   i   =   0   then   i   :=   12;  
   
  Top

8 楼rst_2828(海岛管理员)回复于 2003-12-18 13:44:03 得分 0

uses   DateUtils  
  提示"file   not   found:'DateUtils.dcu'",怎么办啊?Top

9 楼aiirii(ari-http://spaces.msn.com/members/aiirii/)回复于 2003-12-18 13:47:04 得分 0

你有的是delphi   几啊??   你在那裹uses???Top

10 楼rst_2828(海岛管理员)回复于 2003-12-18 13:52:06 得分 0

delphi   5  
  我在interface后面usesTop

11 楼zzllabc(抱朴子--清心释累,绝率忘情)回复于 2003-12-18 14:02:01 得分 0

Delphi   5没有这个单元,这个函数是6里的。Top

12 楼zzllabc(抱朴子--清心释累,绝率忘情)回复于 2003-12-18 14:04:26 得分 0

{   ***********************************************************************   }  
  {                                                                                                                                                   }  
  {   Delphi   Runtime   Library                                                                                                     }  
  {                                                                                                                                                   }  
  {   Copyright   (c)   1995-2001   Borland   Software   Corporation                                         }  
  {                                                                                                                                                   }  
  {   ***********************************************************************   }  
   
  {*******************************************************}  
  {               Date/time   Utilities   Unit                                                 }  
  {*******************************************************}  
   
  {   The   following   unit   is   ISO   8601   compliant.     What   that   means   is   this   unit  
      considers   Monday   the   first   day   of   the   week   (5.2.3).     Additionally   ISO   8601  
      dictates   the   following   "the   first   calendar   week   of   the   year   is   the   one  
      that   includes   the   first   Thursday   of   that   year"   (3.17).     In   other   words   the  
      first   week   of   the   week   is   the   first   one   that   has   four   or   more   days.     For  
      more   information   about   ISO   8601   see:   http://www.iso.ch/markete/8601.pdf  
   
      The   functions   most   impacted   by   ISO   8601   are   marked   as   such   in   the   interface  
      section.  
   
      The   functions   marked   with   "ISO   8601x"   are   not   directly   covered   by   ISO   8601  
      but   their   functionality   is   a   logical   extension   to   the   standard.  
   
      Some   of   the   functions,   concepts   or   constants   in   this   unit   were   provided   by  
      Jeroen   W.   Pluimers   (http://www.all-im.com),   Glenn   Crouch,   Rune   Moberg   and  
      Ray   Lischner   (http://www.tempest-sw.com).  
   
      The   Julian   Date   and   Modified   Julian   Date   functions   are   based   on   code  
      from   NASA's   SOHO   site   (http://sohowww.nascom.nasa.gov/solarsoft/gen/idl/time)  
      in   which   they   credit   the   underlying   algorithms   as   by   Fliegel   and   Van  
      Flandern   (1968)   which   was   reprinted   in   the   Explanatory   Supplement   to   the  
      Astronomical   Almanac,   1992.  
   
      Julian   Date   and   Modified   Julian   Date   is   discussed   in   some   detail   on   the  
      US   Naval   Observatory   Time   Service   site   (http://tycho.usno.navy.mil/mjd.html).  
      Additional   information   can   be   found   at   (http://www.treasure-troves.com/astro).  
  }  
   
  unit   DateUtils;  
   
  interface  
   
  uses  
      SysUtils,   Math,   Types;  
   
  {   Simple   trimming   functions   }  
   
  function   DateOf(const   AValue:   TDateTime):   TDateTime;  
  function   TimeOf(const   AValue:   TDateTime):   TDateTime;  
   
  {   Misc   functions   }  
   
  function   IsInLeapYear(const   AValue:   TDateTime):   Boolean;  
  function   IsPM(const   AValue:   TDateTime):   Boolean;  
  function   IsValidDate(const   AYear,   AMonth,   ADay:   Word):   Boolean;  
  function   IsValidTime(const   AHour,   AMinute,   ASecond,   AMilliSecond:   Word):   Boolean;  
  function   IsValidDateTime(const   AYear,   AMonth,   ADay,   AHour,   AMinute,   ASecond,  
      AMilliSecond:   Word):   Boolean;  
  function   IsValidDateDay(const   AYear,   ADayOfYear:   Word):   Boolean;  
  function   IsValidDateWeek(const   AYear,   AWeekOfYear,                                         {ISO   8601}  
      ADayOfWeek:   Word):   Boolean;  
  function   IsValidDateMonthWeek(const   AYear,   AMonth,   AWeekOfMonth,           {ISO   8601x}  
      ADayOfWeek:   Word):   Boolean;  
  function   WeeksInYear(const   AValue:   TDateTime):   Word;                                     {ISO   8601}  
  function   WeeksInAYear(const   AYear:   Word):   Word;                                               {ISO   8601}  
  function   DaysInYear(const   AValue:   TDateTime):   Word;  
  function   DaysInAYear(const   AYear:   Word):   Word;  
  function   DaysInMonth(const   AValue:   TDateTime):   Word;  
  function   DaysInAMonth(const   AYear,   AMonth:   Word):   Word;  
  function   Today:   TDateTime;  
  function   Yesterday:   TDateTime;  
  function   Tomorrow:   TDateTime;  
  function   IsToday(const   AValue:   TDateTime):   Boolean;  
  function   IsSameDay(const   AValue,   ABasis:   TDateTime):   Boolean;  
   
  {   Pick-a-field   functions   }  
   
  function   YearOf(const   AValue:   TDateTime):   Word;  
  function   MonthOf(const   AValue:   TDateTime):   Word;  
  function   WeekOf(const   AValue:   TDateTime):   Word;                                               {ISO   8601}  
  function   DayOf(const   AValue:   TDateTime):   Word;  
  function   HourOf(const   AValue:   TDateTime):   Word;  
  function   MinuteOf(const   AValue:   TDateTime):   Word;  
  function   SecondOf(const   AValue:   TDateTime):   Word;  
  function   MilliSecondOf(const   AValue:   TDateTime):   Word;  
   
  {   Start/End   functions   }  
   
  function   StartOfTheYear(const   AValue:   TDateTime):   TDateTime;  
  function   EndOfTheYear(const   AValue:   TDateTime):   TDateTime;  
  function   StartOfAYear(const   AYear:   Word):   TDateTime;  
  function   EndOfAYear(const   AYear:   Word):   TDateTime;  
   
  function   StartOfTheMonth(const   AValue:   TDateTime):   TDateTime;  
  function   EndOfTheMonth(const   AValue:   TDateTime):   TDateTime;  
  function   StartOfAMonth(const   AYear,   AMonth:   Word):   TDateTime;  
  function   EndOfAMonth(const   AYear,   AMonth:   Word):   TDateTime;  
   
  function   StartOfTheWeek(const   AValue:   TDateTime):   TDateTime;                     {ISO   8601}  
  function   EndOfTheWeek(const   AValue:   TDateTime):   TDateTime;                         {ISO   8601}  
  function   StartOfAWeek(const   AYear,   AWeekOfYear:   Word;                                   {ISO   8601}  
      const   ADayOfWeek:   Word   =   1):   TDateTime;  
  function   EndOfAWeek(const   AYear,   AWeekOfYear:   Word;                                       {ISO   8601}  
      const   ADayOfWeek:   Word   =   7):   TDateTime;  
   
  function   StartOfTheDay(const   AValue:   TDateTime):   TDateTime;  
  function   EndOfTheDay(const   AValue:   TDateTime):   TDateTime;  
  function   StartOfADay(const   AYear,   AMonth,   ADay:   Word):   TDateTime;   overload;  
  function   EndOfADay(const   AYear,   AMonth,   ADay:   Word):   TDateTime;   overload;  
  function   StartOfADay(const   AYear,   ADayOfYear:   Word):   TDateTime;   overload;  
  function   EndOfADay(const   AYear,   ADayOfYear:   Word):   TDateTime;   overload;  
   
  {   This   of   that   functions   }  
  Top

13 楼zzllabc(抱朴子--清心释累,绝率忘情)回复于 2003-12-18 14:05:56 得分 0

 
  function   MonthOfTheYear(const   AValue:   TDateTime):   Word;  
  function   WeekOfTheYear(const   AValue:   TDateTime):   Word;   overload;             {ISO   8601}  
  function   WeekOfTheYear(const   AValue:   TDateTime;                                               {ISO   8601}  
      var   AYear:   Word):   Word;   overload;  
  function   DayOfTheYear(const   AValue:   TDateTime):   Word;  
  function   HourOfTheYear(const   AValue:   TDateTime):   Word;  
  function   MinuteOfTheYear(const   AValue:   TDateTime):   LongWord;  
  function   SecondOfTheYear(const   AValue:   TDateTime):   LongWord;  
  function   MilliSecondOfTheYear(const   AValue:   TDateTime):   Int64;  
   
  function   WeekOfTheMonth(const   AValue:   TDateTime):   Word;   overload;         {ISO   8601x}  
  function   WeekOfTheMonth(const   AValue:   TDateTime;   var   AYear,                     {ISO   8601x}  
      AMonth:   Word):   Word;   overload;  
  function   DayOfTheMonth(const   AValue:   TDateTime):   Word;  
  function   HourOfTheMonth(const   AValue:   TDateTime):   Word;  
  function   MinuteOfTheMonth(const   AValue:   TDateTime):   Word;  
  function   SecondOfTheMonth(const   AValue:   TDateTime):   LongWord;  
  function   MilliSecondOfTheMonth(const   AValue:   TDateTime):   LongWord;  
   
  function   DayOfTheWeek(const   AValue:   TDateTime):   Word;                                   {ISO   8601}  
  function   HourOfTheWeek(const   AValue:   TDateTime):   Word;                                 {ISO   8601}  
  function   MinuteOfTheWeek(const   AValue:   TDateTime):   Word;                             {ISO   8601}  
  function   SecondOfTheWeek(const   AValue:   TDateTime):   LongWord;                     {ISO   8601}  
  function   MilliSecondOfTheWeek(const   AValue:   TDateTime):   LongWord;           {ISO   8601}  
   
  function   HourOfTheDay(const   AValue:   TDateTime):   Word;  
  function   MinuteOfTheDay(const   AValue:   TDateTime):   Word;  
  function   SecondOfTheDay(const   AValue:   TDateTime):   LongWord;  
  function   MilliSecondOfTheDay(const   AValue:   TDateTime):   LongWord;  
   
  function   MinuteOfTheHour(const   AValue:   TDateTime):   Word;  
  function   SecondOfTheHour(const   AValue:   TDateTime):   Word;  
  function   MilliSecondOfTheHour(const   AValue:   TDateTime):   LongWord;  
   
  function   SecondOfTheMinute(const   AValue:   TDateTime):   Word;  
  function   MilliSecondOfTheMinute(const   AValue:   TDateTime):   LongWord;  
   
  function   MilliSecondOfTheSecond(const   AValue:   TDateTime):   Word;  
   
  {   Range   checking   functions   }  
   
  function   WithinPastYears(const   ANow,   AThen:   TDateTime;  
      const   AYears:   Integer):   Boolean;  
  function   WithinPastMonths(const   ANow,   AThen:   TDateTime;  
      const   AMonths:   Integer):   Boolean;  
  function   WithinPastWeeks(const   ANow,   AThen:   TDateTime;  
      const   AWeeks:   Integer):   Boolean;  
  function   WithinPastDays(const   ANow,   AThen:   TDateTime;  
      const   ADays:   Integer):   Boolean;  
  function   WithinPastHours(const   ANow,   AThen:   TDateTime;  
      const   AHours:   Int64):   Boolean;  
  function   WithinPastMinutes(const   ANow,   AThen:   TDateTime;  
      const   AMinutes:   Int64):   Boolean;  
  function   WithinPastSeconds(const   ANow,   AThen:   TDateTime;  
      const   ASeconds:   Int64):   Boolean;  
  function   WithinPastMilliSeconds(const   ANow,   AThen:   TDateTime;  
      const   AMilliSeconds:   Int64):   Boolean;  
   
  {   Range   query   functions   }  
   
  function   YearsBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   MonthsBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   WeeksBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   DaysBetween(const   ANow,   AThen:   TDateTime):   Integer;  
  function   HoursBetween(const   ANow,   AThen:   TDateTime):   Int64;  
  function   MinutesBetween(const   ANow,   AThen:   TDateTime):   Int64;  
  function   SecondsBetween(const   ANow,   AThen:   TDateTime):   Int64;  
  function   MilliSecondsBetween(const   ANow,   AThen:   TDateTime):   Int64;  
   
  {   Range   spanning   functions   }  
  {   YearSpan   and   MonthSpan   are   approximates,   not   exact   but   pretty   darn   close   }  
  function   YearSpan(const   ANow,   AThen:   TDateTime):   Double;  
  function   MonthSpan(const   ANow,   AThen:   TDateTime):   Double;  
  function   WeekSpan(const   ANow,   AThen:   TDateTime):   Double;  
  function   DaySpan(const   ANow,   AThen:   TDateTime):   Double;  
  function   HourSpan(const   ANow,   AThen:   TDateTime):   Double;  
  function   MinuteSpan(const   ANow,   AThen:   TDateTime):   Double;  
  function   SecondSpan(const   ANow,   AThen:   TDateTime):   Double;  
  function   MilliSecondSpan(const   ANow,   AThen:   TDateTime):   Double;  
   
  {   Increment/decrement   datetime   fields   }  
   
  function   IncYear(const   AValue:   TDateTime;  
      const   ANumberOfYears:   Integer   =   1):   TDateTime;  
  //   function   IncMonth   is   in   SysUtils  
  function   IncWeek(const   AValue:   TDateTime;  
      const   ANumberOfWeeks:   Integer   =   1):   TDateTime;  
  function   IncDay(const   AValue:   TDateTime;  
      const   ANumberOfDays:   Integer   =   1):   TDateTime;  
  function   IncHour(const   AValue:   TDateTime;  
      const   ANumberOfHours:   Int64   =   1):   TDateTime;  
  function   IncMinute(const   AValue:   TDateTime;  
      const   ANumberOfMinutes:   Int64   =   1):   TDateTime;  
  function   IncSecond(const   AValue:   TDateTime;  
      const   ANumberOfSeconds:   Int64   =   1):   TDateTime;  
  function   IncMilliSecond(const   AValue:   TDateTime;  
      const   ANumberOfMilliSeconds:   Int64   =   1):   TDateTime;  
   
  {   Unified   encode/decode   functions   that   deal   with   all   datetime   fields   at   once   }  
   
  function   EncodeDateTime(const   AYear,   AMonth,   ADay,   AHour,   AMinute,   ASecond,  
      AMilliSecond:   Word):   TDateTime;  
  procedure   DecodeDateTime(const   AValue:   TDateTime;   out   AYear,   AMonth,   ADay,  
      AHour,   AMinute,   ASecond,   AMilliSecond:   Word);  
   
  {   Encode/decode   functions   that   work   with   week   of   year   and   day   of   week   }  
   
  function   EncodeDateWeek(const   AYear,   AWeekOfYear:   Word;                               {ISO   8601}  
      const   ADayOfWeek:   Word   =   1):   TDateTime;  
  procedure   DecodeDateWeek(const   AValue:   TDateTime;   out   AYear,                     {ISO   8601}  
      AWeekOfYear,   ADayOfWeek:   Word);  
   
  {   Encode/decode   functions   that   work   with   day   of   year   }  
   
  function   EncodeDateDay(const   AYear,   ADayOfYear:   Word):   TDateTime;  
  procedure   DecodeDateDay(const   AValue:   TDateTime;   out   AYear,   ADayOfYear:   Word);  
   
  {   Encode/decode   functions   that   work   with   week   of   month   }  
   
  function   EncodeDateMonthWeek(const   AYear,   AMonth,   AWeekOfMonth,             {ISO   8601x}  
      ADayOfWeek:   Word):   TDateTime;  
  procedure   DecodeDateMonthWeek(const   AValue:   TDateTime;                               {ISO   8601x}  
      out   AYear,   AMonth,   AWeekOfMonth,   ADayOfWeek:   Word);  
   
  {   The   following   functions   are   similar   to   the   above   ones   except   these   don't  
      generated   exceptions   on   failure,   they   return   false   instead   }  
   
  function   TryEncodeDateTime(const   AYear,   AMonth,   ADay,   AHour,   AMinute,   ASecond,  
      AMilliSecond:   Word;   out   AValue:   TDateTime):   Boolean;  
  function   TryEncodeDateWeek(const   AYear,   AWeekOfYear:   Word;                         {ISO   8601}  
      out   AValue:   TDateTime;   const   ADayOfWeek:   Word   =   1):   Boolean;  
  function   TryEncodeDateDay(const   AYear,   ADayOfYear:   Word;  
      out   AValue:   TDateTime):   Boolean;  
  function   TryEncodeDateMonthWeek(const   AYear,   AMonth,   AWeekOfMonth,       {ISO   8601x}  
      ADayOfWeek:   Word;   var   AValue:   TDateTime):   Boolean;  
  Top

14 楼xinshiji(自由我有)回复于 2003-12-18 14:06:58 得分 0

uses   DateUtils  
   
  MonthOf(now)   -   1  
  Top

15 楼zzllabc(抱朴子--清心释累,绝率忘情)回复于 2003-12-18 14:08:02 得分 0

>>>连续的回复不能超过3次  
   
   
  Sorry,本想把这个单元给你贴上来,却不让连续回复,只有你自己去找了。Top

相关问题

  • 请...问... 有给出年月 获得指定月份的天数, 有库函数吗?
  • Delphi有无取得日期月份和年份的函数?
  • 求函数,直接取出月份,年份,不要用copy()
  • 求:取得月份的第一天和最后天的函数
  • 用ASP函数取得当前系统月份
  • 怎样获得函数自己的函数名。
  • 如何利用时间函数得到上个月的第一天和上个月的最后一天??
  • 什么函数能获得本机ip?
  • 有获得毫秒的函数吗
  • 如何获得模版函数指针

关键词

  • word
  • tdatetime
  • avalue
  • anow
  • ayear
  • athen
  • const
  • amonth
  • adayofweek
  • iso8601

得分解答快速导航

  • 帖主:rst_2828

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo