![](http://oshiete.xgoo.jp/images/v2/pc/qa/question_title.png?e8efa67)
No.1ベストアンサー
- 回答日時:
私かDelphiで使っているルーチンを抜き出してみました
閏年の判定とか、通算日付の計算とか必要となります。
月が何日まであるかを知るルーチン
Get_LastDay_by_YYMMDD
曜日を判定するルーチン
Get_DAYNUMBER_by_4YMMDD
以上です、あとは、自分で以下を解析してみて下さい
尚、Win32等の機種依存のルーチンは使っていません
uses
SysUtils,Math;
const
BASE4DYEAR = 1973; // 00000850
NEXTCENTURY = 2100;
MatuBi :array [0..1] of array [1..12] of integer =
( (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) );
RuisBi :array [0..1] of array [0..12] of integer =
( ( 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365),
( 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366) );
function Leap(iYYYY: integer) :integer; // 0 :平年 1 :閏年
var
i, ii :integer;
begin
result := 0;
i := iYYYY mod 4;
if i <> 0 then exit;
i := iYYYY mod 100;
if (i = 0) then
begin
ii := iYYYY mod 400;
if (ii = 0) then
begin
result := 1;
exit;
end else
begin
result := 0;
end;
end else
begin
result := 1;
exit;
end;
end;
function Check_4YMMDD(iY, iM, iD :integer) :boolean;
var
iLastDD :integer;
begin
result := false;
if ((iY < 0) or (iM <= 0) or (iD <= 0)) then exit;
if (iM < 1) or (iM > 12) then exit;
iLastDD := MatuBi [Leap (iY), iM];
if (iD < 1) or (iD > iLastDD) then exit;
result := true;
end;
function Check_4YDDD(iY, iD :integer) :boolean;
var
ir :integer;
begin
result := false;
if ((iY <= 0) or (iD <= 0)) then exit;
ir := Leap (iY);
if (ir = 0) then
begin
if (iD > 365) then exit;
end else
begin
if (iD > 366) then exit;
end;
result := true;
end;
function Get_LastDay_by_4YMMDD(i4YMMDD :integer) :integer;
var
iYY, iMM :integer;
iLastDD :integer;
begin
result := -1;
iYY := i4YMMDD div 10000;
iMM := (i4YMMDD mod 10000) div 100;
if ((iYY < 0) or (iMM <= 0)) then exit;
if ((iMM < 1) or (iMM > 12)) then exit;
iLastDD := MatuBi [Leap (iYY), iMM];
result := (i4YMMDD div 100) * 100 + iLastDD;
end;
function Get_4YDDD_by_4YMMDD(i4YMMDD :integer) :integer;
var
br :boolean;
i, iYY, iMM, iDD :integer;
begin
result := -1;
iYY := (i4YMMDD div 10000);
iMM := (i4YMMDD mod 10000) div 100;
iDD := (i4YMMDD mod 100);
br := Check_4YMMDD (iYY, iMM, iDD);
if not br then exit;
i := RuisBi [Leap(iYY), (iMM - 1)] + iDD;
result := iYY * 1000 + i;
end;
function Get_ABS73_by_4YDDD(i4YDDD :integer) :integer;
var
br :boolean;
iYYYY, iDDD, iDays :integer;
rYYYY :Extended;
begin
Get_ABS73_by_4YDDD := -1;
iYYYY := i4YDDD div 1000;
iDDD := i4YDDD mod 1000;
br := Check_4YDDD (iYYYY, iDDD);
if not br then exit;
if (iYYYY < BASE4DYEAR) or (iYYYY >= NEXTCENTURY) then exit;
rYYYY := (iYYYY - BASE4DYEAR) * 365.25; // Ok To 2099
iDays := Floor(rYYYY) + iDDD;
Get_ABS73_by_4YDDD := iDays;
end;
function Get_DAYNUMBER_by_4YDDD(i4YDDD :integer) :integer;
var
iABS73, iDayNum :integer;
begin
Get_DAYNUMBER_by_4YDDD := -1;
iABS73 := Get_ABS73_by_4YDDD(i4YDDD);
if (iABS73 = -1) then exit;
iDayNum := iABS73 mod 7;
Get_DAYNUMBER_by_4YDDD := iDayNum;
end;
function Get_DAYNUMBER_by_4YMMDD(i4YMMDD :integer) :integer;
var
i4YDDD, iDayNum :integer;
begin
Get_DAYNUMBER_by_4YMMDD := -1;
i4YDDD := Get_4YDDD_by_4YMMDD(i4YMMDD);
if (i4YDDD = -1) then exit;
iDayNum := Get_DAYNUMBER_by_4YDDD(i4YDDD);
Get_DAYNUMBER_by_4YMMDD := iDayNum;
end;
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- Java Java、配列の問題を教えて欲しいです。 ・日、月、火、水、木、金、土 ・各曜日の英語 を2次元配列 2 2023/07/10 19:14
- Excel(エクセル) エクセルでカレンダーを作りたい 5 2023/05/16 07:32
- C言語・C++・C# [C言語] コメント文字列を無視して、数値データを読み込むプログラム部分について 5 2022/10/05 11:03
- 英語 【 論・表 英訳 】 問題 A:次の月曜日に東京を訪れる予定なんだ。会えない? B:運がいい。私は1 2 2022/07/24 21:55
- Windows 10 windows11 update の「更新の再開」について初歩的な質問なのですが 1 2022/10/19 00:57
- その他(プログラミング・Web制作) Python3プログラムについて 4 2023/05/21 14:55
- C言語・C++・C# C言語 3 2022/10/04 15:07
- ダイヤルアップ Raspberry Piでアナログモデム経由で音声再生 1 2022/05/20 18:01
- Access(アクセス) Access DTPickerの初期表示月を変えたい 1 2022/08/02 08:55
- Visual Basic(VBA) Vba UserFormを前面に出す方法を教えてください 1 2023/08/17 11:08
関連するカテゴリからQ&Aを探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
subsequentとnextの違いってな...
-
タイムアウトする仕組みを作りたい
-
vbsのmsgboxランダム表示について
-
レコードセットにnullの場合
-
VBA public変数はどのようなこ...
-
他のフォームから別のフォーム...
-
Functionの戻り値を配列にした...
-
C#のループでtextboxに値を入れ...
-
String型の値にスラッシュをつ...
-
【VB.NET】テキストボックスに...
-
【VB6.0】 あるフォームから他...
-
VB.NETでのイベントの途中終了
-
HTML + VBScript で Sleep でき...
-
合計値の反映
-
Vba テキストボックスの文字列...
-
ClickとChangeイベントの違いは...
-
エクセルVBAでテキストボッ...
-
ドラゴン曲線を再帰で書く
-
エクセル・VBAでテキストボック...
-
C言語のサフィックスについて
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
レコードセットにnullの場合
-
タイムアウトする仕組みを作りたい
-
subsequentとnextの違いってな...
-
verilogのcase文
-
日付の重複
-
vbsのmsgboxランダム表示について
-
リスト間のアイテム移動について
-
TreeViewのTag情報取得
-
pascalでの二分探索(バイナリ...
-
delphi
-
Pascalのプログラムです
-
C言語のプログラムで...
-
【FPGA】VHDLのprocessとevent
-
エクセルVBAついて ①if•••••the...
-
FORTRAN77でプログラミング
-
クラスモジュールの処理
-
EXCEL VBA 文字 アドレス 検...
-
パスカル言語
-
Verilog-HDLによる設計において
-
なんで? cEn-P^-1AP=P^-1(cEn-AP)
おすすめ情報