Thread: I use Java but...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    4

    Question I use Java but...

    I canīt change system date in Java, that's why I'm here. Please, I need to change system date(windows) to a specific date, then execute a program and finally restore the original date of the system. How can I do it?
    Please specify which C compiler should use.

    Thanks.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You need a windows compiler (VC++,Borland Builder, DevC++...) and you need windows.h and you need to call SetSystemTime()

    More info on MSDN

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Why? Are you trying to get round a time limited software trial or something?

    Anyway, what your asking is OS specific, you'll need to find the Windows API that will do that for you (this is a educated guess!).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    4

    Thumbs up done!

    Ok, I found a solution. It's chep but works fine:

    before running the aplication:

    #include <io.h>
    main()
    {
    int f;
    f=creat("ro.txt",0);
    close(f);
    printf("Cambio fecha...");
    system("date 02/01/2002");
    }

    after:

    #include <string.h>
    #include <io.h>
    #include <stdlib.h>
    #include <dos.h>
    main()
    {
    int f;
    int i;
    char *s = "date ";
    char sAnio[5];
    char sDia[11];
    char sMes[3];
    struct ftime ft;
    sleep(10);
    f=open("ro.txt",0);
    getftime(f,&ft);
    i = ft.ft_year + 1980;
    itoa(i,sAnio,10);
    i = ft.ft_month;
    itoa(i,sMes,10);
    i = ft.ft_day;
    itoa(i,sDia,10);
    strcat(sDia,"/");
    strcat(sDia,sMes);
    strcat(sDia,"/");
    strcat(sDia,sAnio);
    strcat(s,sDia);
    close(f);
    system(s);
    }

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    4

    Lightbulb this one is better

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <dos.h>
    #include <time.h>

    main()
    {
    int i;
    char *s = "date ";
    char sAnio[5];
    char sDia[11];
    char sMes[3];
    struct ftime ft;
    time_t tmt;
    struct tm *tms;

    tmt = time(&tmt);
    tms = localtime(&tmt);
    tms->tm_mon++;

    printf("Cambio fecha...");
    system("date 02/01/2002");

    system("c:\\id\\id.exe");

    sleep(15);

    i = tms->tm_year + 1900;
    itoa(i,sAnio,10);
    i = tms->tm_mon;
    itoa(i,sMes,10);
    i = tms->tm_mday;
    itoa(i,sDia,10);

    printf("AĪo:%s\n", sAnio);
    printf("Mes:%s\n", sMes);
    printf("Dia:%s\n", sDia);

    strcat(sDia,"/");
    strcat(sDia,sMes);
    strcat(sDia,"/");
    strcat(sDia,sAnio);
    strcat(s,sDia);

    printf("Fecha:%s\n",s);
    system(s);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  2. First Java Class at college
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 09-29-2004, 10:38 PM
  3. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  4. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM
  5. C or Java as a first language
    By CorJava in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 10-23-2002, 05:12 PM