Revision 7e0af5d0

b/hw/mc146818rtc.c
393 393
    int val;
394 394

  
395 395
    /* set the CMOS date */
396
    time(&ti);
397
    if (rtc_utc)
396
    if (rtc_start_date == -1) {
397
        time(&ti);
398
        if (rtc_utc)
399
            tm = gmtime(&ti);
400
        else
401
            tm = localtime(&ti);
402
    } else {
403
        ti = rtc_start_date;
398 404
        tm = gmtime(&ti);
399
    else
400
        tm = localtime(&ti);
405
    }
401 406
    rtc_set_date(s, tm);
402 407

  
403 408
    val = to_bcd(s, (tm->tm_year / 100) + 19);
b/qemu-doc.texi
268 268
time). This option is needed to have correct date in MS-DOS or
269 269
Windows.
270 270

  
271
@item -startdate date
272
Set the initial date of the real time clock. Valid format for
273
@var{date} are: @code{now} or @code{2006-06-17T16:01:21} or
274
@code{2006-06-17}. The default value is @code{now}.
275

  
271 276
@item -pidfile file
272 277
Store the QEMU process PID in @var{file}. It is useful if you launch QEMU
273 278
from a script.
b/vl.c
174 174
NICInfo nd_table[MAX_NICS];
175 175
int vm_running;
176 176
int rtc_utc = 1;
177
int rtc_start_date = -1; /* -1 means now */
177 178
int cirrus_vga_enabled = 1;
178 179
int vmsvga_enabled = 0;
179 180
#ifdef TARGET_SPARC
......
7212 7213
    QEMU_OPTION_prom_env,
7213 7214
    QEMU_OPTION_old_param,
7214 7215
    QEMU_OPTION_clock,
7216
    QEMU_OPTION_startdate,
7215 7217
};
7216 7218

  
7217 7219
typedef struct QEMUOption {
......
7318 7320
    { "old-param", 0, QEMU_OPTION_old_param },
7319 7321
#endif
7320 7322
    { "clock", HAS_ARG, QEMU_OPTION_clock },
7323
    { "startdate", HAS_ARG, QEMU_OPTION_startdate },
7321 7324
    { NULL },
7322 7325
};
7323 7326

  
......
8107 8110
            case QEMU_OPTION_clock:
8108 8111
                configure_alarms(optarg);
8109 8112
                break;
8113
            case QEMU_OPTION_startdate:
8114
                {
8115
                    struct tm tm;
8116
                    if (!strcmp(optarg, "now")) {
8117
                        rtc_start_date = -1;
8118
                    } else {
8119
                        if (sscanf(optarg, "%d-%d-%dT%d:%d:%d",
8120
                               &tm.tm_year,
8121
                               &tm.tm_mon,
8122
                               &tm.tm_mday,
8123
                               &tm.tm_hour,
8124
                               &tm.tm_min,
8125
                               &tm.tm_sec) == 6) {
8126
                            /* OK */
8127
                        } else if (sscanf(optarg, "%d-%d-%d",
8128
                                          &tm.tm_year,
8129
                                          &tm.tm_mon,
8130
                                          &tm.tm_mday) == 3) {
8131
                            tm.tm_hour = 0;
8132
                            tm.tm_min = 0;
8133
                            tm.tm_sec = 0;
8134
                        } else {
8135
                            goto date_fail;
8136
                        }
8137
                        tm.tm_year -= 1900;
8138
                        tm.tm_mon--;
8139
                        rtc_start_date = timegm(&tm);
8140
                        if (rtc_start_date == -1) {
8141
                        date_fail:
8142
                            fprintf(stderr, "Invalid date format. Valid format are:\n"
8143
                                    "'now' or '2006-06-17T16:01:21' or '2006-06-17'\n");
8144
                            exit(1);
8145
                        }
8146
                    }
8147
                }
8148
                break;
8110 8149
            }
8111 8150
        }
8112 8151
    }
b/vl.h
166 166
extern int ram_size;
167 167
extern int bios_size;
168 168
extern int rtc_utc;
169
extern int rtc_start_date;
169 170
extern int cirrus_vga_enabled;
170 171
extern int vmsvga_enabled;
171 172
extern int graphic_width;

Also available in: Unified diff