Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current time in Google spreadsheet using script editor?

There is an option to write a script and bind it to a trigger. The question is, how to get the current time in the script body?

function myFunction() {    var currentTime = // <<???  } 
like image 538
J.Olufsen Avatar asked Apr 16 '12 21:04

J.Olufsen


People also ask

How do I extract time from Google Sheets?

Method 1: Use SPLIT Function On cell B2, type =SPLIT(A2, “ ”). This will automatically write the date in cell B2 and the time in cell C2. Don't forget the space between the “ ”.


1 Answers

use the JavaScript Date() object. There are a number of ways to get the time, date, timestamps, etc from the object. (Reference)

function myFunction() {   var d = new Date();   var timeStamp = d.getTime();  // Number of ms since Jan 1, 1970    // OR:    var currentTime = d.toLocaleTimeString(); // "12:35 PM", for instance } 
like image 86
Jeff B Avatar answered Sep 29 '22 13:09

Jeff B