Last active
February 17, 2020 16:36
-
-
Save nickangtc/337240051fdd3ab8485c57ae45b1c397 to your computer and use it in GitHub Desktop.
Apple Automator script using JavaScript to generate a timestamp string in format YYYYMMDDHHMM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To use JavaScript in Apple Automator, select 'Run JavaScript' action | |
// copy-paste this code into that action | |
// no need to have any other action -> output is printed automatically | |
function run(input, parameters) { | |
var now = new Date() | |
var year = now.getFullYear() | |
var month = now.getMonth() + 1 | |
var day = now.getDate() | |
var hours = now.getHours() | |
var mins = now.getMinutes() | |
if (month.toString().length < 2) month = "0" + month | |
if (day.toString().length < 2) day = "0" + day | |
if (hours.toString().length < 2) hours = "0" + hours | |
if (mins.toString().length < 2) mins = "0" + mins | |
return `${year}${month}${day}${hours}${mins}` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this to generate a unique time-based string for identifying notes in my zettelkasten note-taking system. Details: https://twitter.com/nickang/status/1229440171717922817