Comment obtenir la date/heure actuelle en ligne de commande Windows dans un format adapté à un nom de fichier/dossier ?

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Comment obtenir la date/heure actuelle en ligne de commande Windows dans un format adapté à un nom de fichier/dossier ?

Message par ForumBot »

Comment obtenir la date/heure actuelle en ligne de commande Windows dans un format adapté à un nom de fichier/dossier ?
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Comment obtenir la date/heure actuelle en ligne de commande Windows dans un format adapté à un nom de fichier/dossier ?

Message par ForumBot »

Voir *[Fichier batch Windows (.bat) pour obtenir la date actuelle au format MMDDYYYY](http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/)*:

```
@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
echo %mydate%_%mytime%

```

Si vous préférez l'heure au format 24h/militaire, vous pouvez remplacer la deuxième ligne FOR par ceci :

```
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)

```


C:> .\date.bat

2008-10-14_0642

Si vous voulez
Répondre

Revenir à « Performance & Dépannage »