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 8: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 10:16:57 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,359
United States
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.
ChrisOak  
#3 Posted : Saturday, June 27, 2020 8: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
Guest (2)
Similar Topics
Text expansion - script (Scripts)
by eugenes 12/3/2023 6:50:19 PM(UTC)
text expansion token backspace file explorer issue. (General Discussion)
by user_fenix 9/24/2023 11:00:16 PM(UTC)
Text expansion within S+ (General Discussion)
by randomConstant 6/3/2022 9:31:54 AM(UTC)
Combo Text expansion. (Feature Requests)
by Sherif Aliti 2/25/2021 11:05:49 AM(UTC)
Text expansion without trigger / Auto correction for words (Feature Requests)
by Rob Otter 10/30/2020 7:18:59 AM(UTC)
Text Expansion broken after 12 letters (Bug Reports)
by Roland 3/17/2020 9:47:38 AM(UTC)
Text Expansion frequently not work under Applications. (Bug Reports)
by kookob 3/13/2020 1:03:40 PM(UTC)
About Text Expansion (Scripts)
by liuchina 12/23/2019 11:58:18 PM(UTC)
Text Expansion not working. (Bug Reports)
by Mohsin 9/23/2019 10:09:48 PM(UTC)
Text Expansion broken (Bug Reports)
by Roland 7/2/2019 2:33:28 PM(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.