Get current time

Post here if you need help using Actiona
Post Reply
theoth
Posts: 6
Joined: 10 Dec 2017, 01:00

Get current time

Post by theoth »

I was wondering if there is any way to get the current system time as I want to log data to a text file including the current time
Thanks,
Theo
francois
Posts: 456
Joined: 18 Oct 2010, 10:33
Location: France

Re: Get current time

Post by francois »

An example :

Code: Select all

//========
now= new Date();
aaaa = now.getFullYear();
mm = now.getMonth() + 1;
jj =  now.getDate();

hh = now.getHours();
mn =  now.getMinutes();
ss =  now.getSeconds();

date_heure= aaaa + " " + mm + " " + jj + " " + hh + "-" + mn +  "-" +  ss ;
//=========


var  fichier_date_time = new File();
fichier_date_time_chemin_complet= "C:\\temp\\date_time.csv"
fichier_date_time.open(fichier_date_time_chemin_complet,File.WriteOnly | File.Text );

w_art  = date_heure  + "\n";
fichier_date_time.writeText(w_art);

fichier_date_time.close();
MDLE46
Posts: 108
Joined: 11 Nov 2016, 19:06

Re: Get current time

Post by MDLE46 »

Bonjour,

J'ai sauvegardé ce code bien utile dans ma bibliothèque perso.

Ce script écrit dans un fichier texte en écrasant le contenu.

Si ce n'est pas trop compliqué, serai t’il possible d'avoir le même sans écrasement du contenu (en ajoutant à la fin).

Cordialement.

MDLE46.
theoth
Posts: 6
Joined: 10 Dec 2017, 01:00

Re: Get current time

Post by theoth »

MDLE46 wrote: 10 Dec 2017, 20:03 Bonjour,

J'ai sauvegardé ce code bien utile dans ma bibliothèque perso.

Ce script écrit dans un fichier texte en écrasant le contenu.

Si ce n'est pas trop compliqué, serai t’il possible d'avoir le même sans écrasement du contenu (en ajoutant à la fin).

Cordialement.

MDLE46.
im not sure if you attached something to your post, but I cant see anything.
thanks anyway though :)
and thanks for all the help to everyone in this forum!
francois
Posts: 456
Joined: 18 Oct 2010, 10:33
Location: France

Re: Get current time

Post by francois »

Bonjour MDLE46,
Cette semaine, dans le forum en français, je vais mettre un script complet dans la rubrique "Tutos & exemples" :
exemple d'écriture d'un fichier log qui contient la date et l'heure.

Hello theoth,
I responded a little quickly.

To create a log data.

At the beginning of your script, a code action :

Code: Select all

var  fichier_date_time = new File();
fichier_date_time_chemin_complet= "C:\\temp\\date_time.csv"
fichier_date_time.open(fichier_date_time_chemin_complet,File.WriteOnly | File.Text | File.Append  );
After, an other code Action :

Code: Select all

w_art  = date_heure()  + "\n";
fichier_date_time.writeText(w_art);

//========
function date_heure() {
now= new Date();
aaaa = now.getFullYear();
mm = now.getMonth() + 1;
jj =  now.getDate();

hh = now.getHours();
mn =  now.getMinutes();
ss =  now.getSeconds();

zz = aaaa  + " " + mm + " " + jj + " " + hh + "-" + mn +  "-" +  ss ;
return zz
}

At the end of your script, a code Action :

Code: Select all

fichier_date_time.close();
MDLE46
Posts: 108
Joined: 11 Nov 2016, 19:06

Re: Get current time

Post by MDLE46 »

Bonjour François,

Merci pour cet exemple "Ecrire à la suite dans un fichier texte".

C'est simple une fois que l'on a la réponse sous les yeux.
Amen pour Append. J'ai essayé de positionner cet Append dans tous les sens (WriteAppendText, WriteAllAppend ... et autres soluces que j'avais trouvé sur le net). Mais pas comme tu as fais. Encore merci.

Et j'attends avec impatience ton nouveau tuto car je pense qu'il y' aura bien quelque chose à "glaner".

Cordialement
MDLE46
theoth
Posts: 6
Joined: 10 Dec 2017, 01:00

Re: Get current time

Post by theoth »

francois wrote: 11 Dec 2017, 08:38 At the beginning of your script, a code action :

Code: Select all

var  fichier_date_time = new File();
fichier_date_time_chemin_complet= "C:\\temp\\date_time.csv"
fichier_date_time.open(fichier_date_time_chemin_complet,File.WriteOnly | File.Text | File.Append  );
thanks for the help, I was curious if there is a way to read the directory where to save it from an ini.
I cant manage to make it work
francois
Posts: 456
Joined: 18 Oct 2010, 10:33
Location: France

Re: Get current time

Post by francois »

hello,

to create variables in a ini file :

Code: Select all

var file_ini = new IniFile();
file_ini.setSection("gene");
file_ini.setKeyValue("x",1782);
file_ini.setKeyValue("dir_temp","d:/temp");
file_ini.save("C:/test/azerty.ini");

In an other script, to read variables in a ini file :

Code: Select all

var file_ini = new IniFile();
file_ini.load("C:/test/azerty.ini");
file_ini.setSection("gene");
x= file_ini.keyValue("x");
dir_temp= file_ini.keyValue("dir_temp");
Console.print(x)
Console.print(dir_temp)
Post Reply