0

Is it just me or has something in Google changed recently? I have a function that adds a timestamp to edits that was working just fine, and just the other day it broke.

It broke in the sense that it used to stamp the time in my timezone - as is specified by the function formatting I use, Now it appears to be timestamping in GMT instead of GMT-8. Nothing has changed in my script, so what happened?

function happyFunTime() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  var columnNum = r.getColumn();
  var timeLastCalledColumnOffset = getTimeLastCalledColumnOffset();
  var rowNum = r.getRow();

if (rowNum <=1) return;

  timeLastCalledColumnOffset++;
  // set dateCell = the current row at column J
  var dateCell = s.getRange(rowNum, timeLastCalledColumnOffset);


  var tZone= "GMT-8";
  // Format the current date into datetime format 
  var dateTime = Utilities.formatDate(new Date(), tZone, "MMM-dd-yyyy h:mm a");

  // Set the cell value.  Add apostrophe to force text treatment & keep the spreadsheet from reformatting
    dateCell.setValue("'" + dateTime);

}

getTimeLastCalledColumnOffset() is a custom function to return a number of the column that contains the value I'm interested in (J, so 9 in this case).

4

3 に答える 3

3

はい、この文字列「GMT-2」または「GMT-0200」は正常に機能しており、現在は障害があるため、昨日から問題が発生しています。

この行を変更できます:

   var tZone= "GMT-8"

これに

   var tZone= "GMT-08:00"

または、次のコード行でタイムゾーンを取得できます。

  var FUS1 = new Date().toString().substr(25,8);  // I use FUS1 instead of tZone

  // GMT-0800  ->  GMT-08:00 , ...
  var FUS1 = FUS1.substr(0,6) + ':' + FUS1.substr(6)

  // Format the current date into datetime format 
  var dateTime = Utilities.formatDate(new Date(), FUS1 , "MMM-dd-yyyy h:mm a");

または、ここからタイムゾーンを書き込むことができます:

http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

「アメリカ/ドーソン」->-08:00(どこに住んでいるのかわかりません:-()

そしてこのコード:

  var dateTime = Utilities.formatDate(new Date(), "America/Dawson" , "MMM-dd-yyyy h:mm a");

注:DateBox(ラベル、テキストボックスなど)からキャプチャされた日付をフォーマットする場合、最後の行は次のようになります。

   var dateTime = Utilities.formatDate(new Date(e.paramameter.datebox), "America/Dawson" , "MMM-dd-yyyy h:mm 

セルギ

于 2012-12-15T22:12:40.583 に答える
1

含める正しい文字列を取得するもう1つの簡単な解決策は、たとえば私の場合はこれを返し、有効な引数Utilities.formatDate()を使用する ことです。Session.getTimeZone()'Europe/Paris'

于 2012-12-17T10:56:00.533 に答える
0

We can directly change the time zone of spreadsheet using below line

SpreadsheetApp.getActive().setSpreadsheetTimeZone(Session.getScriptTimeZone())

于 2018-01-30T05:42:42.893 に答える