Rank: Newbie
Groups: Approved
Joined: 6/14/2020(UTC) Posts: 2 Location: Berlin
|
Hi everyone!
How can i get date and time as a text expansion.
such as... d# => 26.06.2020 t# => 10:43
warm regards ChrisOak
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,359 Location: Tampa, FL Thanks: 28 times Was thanked: 419 time(s) in 356 post(s)
|
For both of these, select Automation from the Text Expansion Method dropdown, then use the appropriate script below. Date:Code:var d = new Date();
var dateString = ("0" + d.getDate()).slice(-2)
+ "."
+ ("0" + (d.getMonth()+1)).slice(-2)
+ "."
+ d.getFullYear();
sp.SendKeys(dateString);
Time:Code:var d = new Date();
var timeString = ("0" + d.getHours()).slice(-2)
+ ":"
+ ("0" + d.getMinutes()).slice(-2);
sp.SendKeys(timeString);
Note that the spacing so each segment is on a separate line isn't required, I just did that to make it easier to read. The "0" + and slice(-2) segments are to handle padding single digits, so 6 becomes 06. (d.getMonth()+1) : +1 is used because getMonth returns a 0-based value, e.g. January is 0 (zero) and December is 11. The script engine runs JavaScript in the Chrome V8 engine, so any compatible JavaScript to format date/time to strings is acceptable - there are dozens of different ways to achieve this.
|
|
|
|
Rank: Newbie
Groups: Approved
Joined: 6/14/2020(UTC) Posts: 2 Location: Berlin
|
It works! It works! Rob, you are the best! Thanks a lot.
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close