현재 시간을 이쁘게 구하려는데 시간이..

익명 사용자의 이미지

다음과 같이 소스를 작성 하였습니다.
이상하게도 지금 시간만이 이상하게 나옵니다.
즉 시간이 다르게 나옵니다..

#include
#include
#include
#include

int main()
{
time_t clock;
struct tm * tm;
char date[9];
int len;
char * set;
set=(char *)malloc(4);
set = setlocale(LC_TIME,"ko");
printf("Setlocale %d\n",date);
time(&clock);
tm=gmtime(&clock);
len=strftime(date,sizeof(date),"%Y%m%d",tm);
printf("YYYYMMDD%s\n",date);
printf("Length %d",len);

len=strftime(date,sizeof(date),"%H%M%S",tm);
printf("\nHHMMSS%s\n",date);
printf("Length %d\n",len);

exit(0);
}

위와 같이 코드를 작성 하였습니다
결과 화면은 다음과 같습니다.
[blueaqua@ave ~/date]$ date
2001년 10월 4일 목요일 17시 50분 57초 KST
[blueaqua@ave ~/date]$ a.out
Setlocale -1077938508
YYYYMMDD20011004
Length 8
HHMMSS085059
Length 6

왜 시간이 17이 나오질 않고 8로 나왔던 걸까요? 옵션들은 정말로 다 바꾸어
보았는데..ㅠ.ㅠ

익명 사용자의 이미지

음..아마도 setlocale 함수 때문에 시간이 다르게 출력되는것 같은데..

현재 시간을 구하는 문제라면 구지 setlocale 함수를 사용하지 않고

time함수만으로도 충분히 현재 시간을 구할수 있을것 같은데요..

setlocale 함수를 사용한 이유를 잘 모르겠군요..

익명 사용자의 이미지

#include

main()
{

struct tm *t;
time_t tt=time(NULL);
char *tmp;

t=localtime(&tt);
switch (t->tm_wday)
{
case 1
tmp="월";
break;

case 2
tmp="화";
break;
case 3
tmp="수";
break;
case 4
tmp="목";
break;
case 5
tmp="금";
break;
case 6
tmp="토";
break;
case 0
tmp="일";
}
printf("[%d/%d/%d %s %d%d%d]\n",
(t->tm_year)+1900,
(t->tm_mon)+1,
t->tm_mday,
tmp,
t->tm_hour,
t->tm_min,
t->tm_sec);
}

익명 사용자의 이미지

한국은 GMT+9 시간대에 있기 때문에 9 시간을 더해야 올바른 시간이겠죠.

익명 사용자의 이미지

이 함수를 써도 변화가 없네요..

그러면..꼬옥..저 시간에 +9를 해주어야 할까요?
다른 방법은 없을까요??

저렇게 9를 더할려면 스트링을 숫자로->+0->다시 스트링 -> 복사
해주어야 하는데..

혹시나..방법이 있을까 해서 이렇게
죄송을 무릅쓰고 질문을 올립니다..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.