StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ChrisOak  
#1 Posted : Friday, June 26, 2020 2:46:20 AM(UTC)
ChrisOak

Rank: Newbie

Reputation:

Groups: Approved
Joined: 6/14/2020(UTC)
Posts: 2
Germany
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
Rob  
#2 Posted : Friday, June 26, 2020 4:16:57 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 667
United States

Thanks: 13 times
Was thanked: 149 time(s) in 130 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.
ChrisOak  
#3 Posted : Saturday, June 27, 2020 2:03:26 PM(UTC)
ChrisOak

Rank: Newbie

Reputation:

Groups: Approved
Joined: 6/14/2020(UTC)
Posts: 2
Germany
Location: Berlin

It works! It works!
Rob, you are the best!
Thanks a lot.
Users browsing this topic
Similar Topics
Text Expansion broken after 12 letters (Bug Reports)
by Roland 3/17/2020 3:47:38 AM(UTC)
Text Expansion frequently not work under Applications. (Bug Reports)
by kookob 3/13/2020 7:03:40 AM(UTC)
About Text Expansion (Scripts)
by liuchina 12/23/2019 4:58:18 PM(UTC)
Text Expansion not working. (Bug Reports)
by Mohsin 9/23/2019 4:09:48 PM(UTC)
Text Expansion broken (Bug Reports)
by Roland 7/2/2019 8:33:28 AM(UTC)
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.