Q&A

  • C에서 time_t


시간계산을 해야하는데여....

단말기로부터오는 시간 정보를 계산해서 출력해야합니다.

예전엔 C에서 Time_T Type으로 선언해서 계산을 했는데...

델파이에선 이와 같은 Type이 없는 건지... 아님 다른 방법이 있는지 갈켜 주세여...

아래는 예전에 MFC에서 시간을 계산한 Source 입니다. 이것을 Pascal로 바꾸고 시포 여...



------ C Source -----

__int64 time = reset_time; // reset_time은 단말로 부터 들어온 데이터....

time >>= 16;

__int64 time_t = (__int64)(time *1.25) % 1000;

DWord e_time = (DWord)(time / 800);

time_t time_x = (time_t)(e_time + 315964800);



char temp[30];

strcpy(temp, ctime(&time_x));

temp[24] = NULL;

Stamp.Format("%s", temp);

GetDlgItem(IDC_TIME) -> SetWindowText(stamp);

//---------------------------------------------//





2  COMMENTS
  • Profile
    나무.. 2001.10.13 18:47
    일단 TDateTime 이런게 있슴당...



    근데 님께서 쓰신 단말기서 온 데이터가 어떤건지 몰라서리 확답은 몬하겠네여



    년월일시분초 계산은 알아서 하시고 그거 스트링으로 바꾼담에 strtodatetime(..)으로 바꿔 쓰시면 됩니다.



    그리고 한달 늘리구 싶으시면 incMonth(temDate,1), 하루 늘리고 싶으시면 temDate := temDate + 1 (단 temDate는 TDate)



    밑에는 TDateTime 의 도움말 임당... 틈틈이 F1 눌려 보시길 고거이 바이블이죠..



    즐푸하세염...

    ----------

    type TDateTime = type Double;



    Description



    Most VCL objects represent date and time values using the TDateTime type. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is fraction of a 24 hour day that has elapsed.



    Following are some examples of TDateTime values and their corresponding dates and times:



    0 12/30/1899 12:00 am

    2.75 1/1/1900 6:00 pm

    -1.25 12/29/1899 6:00 am

    35065 1/1/1996 12:00 am

    To find the fractional number of days between two dates, simply subtract the two values. Likewise, to increment a date and time value by a certain fractional number of days, simply add the fractional number to the date and time value.



    Note: Delphi 1.0 calculated the date from year 1 instead of from 1899. To convert a Delphi 1.0 date to a Delphi 2.0 date, subtract 693594.0 from the Delphi 1.0 date. The date format changed to be more compatible with OLE 2.0 Automation.



    albireo wrote:

    >

    > 시간계산을 해야하는데여....

    > 단말기로부터오는 시간 정보를 계산해서 출력해야합니다.

    > 예전엔 C에서 Time_T Type으로 선언해서 계산을 했는데...

    > 델파이에선 이와 같은 Type이 없는 건지... 아님 다른 방법이 있는지 갈켜 주세여...

    > 아래는 예전에 MFC에서 시간을 계산한 Source 입니다. 이것을 Pascal로 바꾸고 시포 여...

    >

    > ------ C Source -----

    > __int64 time = reset_time; // reset_time은 단말로 부터 들어온 데이터....

    > time >>= 16;

    > __int64 time_t = (__int64)(time *1.25) % 1000;

    > DWord e_time = (DWord)(time / 800);

    > time_t time_x = (time_t)(e_time + 315964800);

    >

    > char temp[30];

    > strcpy(temp, ctime(&time_x));

    > temp[24] = NULL;

    > Stamp.Format("%s", temp);

    > GetDlgItem(IDC_TIME) -> SetWindowText(stamp);

    > //---------------------------------------------//

    >

    >

  • Profile
    albireo 2001.10.16 17:37
    나무.. wrote:

    > 일단 TDateTime 이런게 있슴당...

    >

    > 근데 님께서 쓰신 단말기서 온 데이터가 어떤건지 몰라서리 확답은 몬하겠네여

    >

    > 년월일시분초 계산은 알아서 하시고 그거 스트링으로 바꾼담에 strtodatetime(..)으로 바꿔 쓰시면 됩니다.

    >

    > 그리고 한달 늘리구 싶으시면 incMonth(temDate,1), 하루 늘리고 싶으시면 temDate := temDate + 1 (단 temDate는 TDate)

    >

    > 밑에는 TDateTime 의 도움말 임당... 틈틈이 F1 눌려 보시길 고거이 바이블이죠..

    >

    > 즐푸하세염...

    > ----------

    > type TDateTime = type Double;

    >

    > Description

    >

    > Most VCL objects represent date and time values using the TDateTime type. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is fraction of a 24 hour day that has elapsed.

    >

    > Following are some examples of TDateTime values and their corresponding dates and times:

    >

    > 0 12/30/1899 12:00 am

    > 2.75 1/1/1900 6:00 pm

    > -1.25 12/29/1899 6:00 am

    > 35065 1/1/1996 12:00 am

    > To find the fractional number of days between two dates, simply subtract the two values. Likewise, to increment a date and time value by a certain fractional number of days, simply add the fractional number to the date and time value.

    >

    > Note: Delphi 1.0 calculated the date from year 1 instead of from 1899. To convert a Delphi 1.0 date to a Delphi 2.0 date, subtract 693594.0 from the Delphi 1.0 date. The date format changed to be more compatible with OLE 2.0 Automation.

    >

    > albireo wrote:

    > >

    > > 시간계산을 해야하는데여....

    > > 단말기로부터오는 시간 정보를 계산해서 출력해야합니다.

    > > 예전엔 C에서 Time_T Type으로 선언해서 계산을 했는데...

    > > 델파이에선 이와 같은 Type이 없는 건지... 아님 다른 방법이 있는지 갈켜 주세여...

    > > 아래는 예전에 MFC에서 시간을 계산한 Source 입니다. 이것을 Pascal로 바꾸고 시포 여...

    > >

    > > ------ C Source -----

    > > __int64 time = reset_time; // reset_time은 단말로 부터 들어온 데이터....

    > > time >>= 16;

    > > __int64 time_t = (__int64)(time *1.25) % 1000;

    > > DWord e_time = (DWord)(time / 800);

    > > time_t time_x = (time_t)(e_time + 315964800);

    > >

    > > char temp[30];

    > > strcpy(temp, ctime(&time_x));

    > > temp[24] = NULL;

    > > Stamp.Format("%s", temp);

    > > GetDlgItem(IDC_TIME) -> SetWindowText(stamp);

    > > //---------------------------------------------//

    > >

    > >



    답변 감사합니다.

    근데 값이 잘 안 나오네여...

    저두 걸 이용해서 상태바에 현재 시간을 출력하고 있는데여...

    건 되는데...

    단말기에서 들어온 값은 잘 안 나와여...

    어디가 이상한 건지....

    항상 "오전 12:00" 이런 값만 찍구 이떠여....흑...

    들어온 값을 바로 TimeToStr(들어온 Data)이러케 하니까....

    이건 들어올 때 당시의 값만 문자로 출력하면 되거덩여....

    어케 하면 저을까여....