I use Java but...

This is a discussion on I use Java but... within the C Programming forums, part of the General Programming Boards category; I canīt change system date in Java, that's why I'm here. Please, I need to change system date(windows) to a ...

  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,789
    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, 03: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, 11: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, 10:07 PM
  4. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 01: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, 06:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21