Google电子邮件脚本更改日期

时间:2018-10-10 09:05:55

标签: javascript email google-apps-script

我正在使用下面的电子邮件发送脚本,将一些日期发送给经过授权的人,格式是google表格

  

DD / MM / YYYY

但是,发送的内容是很长的时间,像这样

  

“ 2019年1月7日星期一00:00:00 GMT-0000(GMT)”

我只需要它来发送单元格中的确切内容,而不更改它,我已经尝试了一些到目前为止还不起作用的事情,我不想仅通过发送显示的内容来更改工作表中的内容。

任何帮助将不胜感激

脚本是

// Scrips for Email sheet PHC main 
// has been sent successfully.
var EMAIL_SENT = "SENT";

function sendEmailshol() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = 5;   // Number of rows to process
  // Fetch the range of cells 
  var dataRange = sheet.getRange(startRow, 1, numRows, 50) ;  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[42] ;  // First column
    var message = 'Hi ' + row[3] + '\n'// Hi then Name from sheet then new line 
    + 'xxx.' + '\n\n' 
    + row[5] + ' To ' + row[6] + ' ' + row[7] + '\n' 
    + '\n\n' 
    + 'Any questions please dont hesitate to give me a call.' + '\n\n' 
    var emailSent = row[43];     // Third column
    if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
      var subject = 'xxx' ;
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 44).setValue(EMAIL_SENT);       // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}

1 个答案:

答案 0 :(得分:2)

您可以在https://developers.google.com/google-ads/scripts/docs/features/dates处查看有关日期格式的信息。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.DetailsActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:toolbarId="@+id/toolbar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_alignParentTop="true" />

            <me.relex.circleindicator.CircleIndicator
                android:id="@+id/indicator"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_alignParentBottom="true"
                android:gravity="top"
                android:paddingBottom="25dp" />

        </RelativeLayout>


    </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_layout" />

    <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    app:layout_anchor="@id/app_bar"
    app:layout_anchorGravity="bottom|end"
    app:srcCompat="@android:drawable/ic_dialog_email" />

 </android.support.design.widget.CoordinatorLayout>

所以您的情况就是...

public class MainActivity extends AppCompatActivity {

private ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_details);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mViewPager = findViewById(R.id.container);

    setupViewPager(mViewPager);
    mViewPager.setCurrentItem(0, true);

    FloatingActionButton fab = (FloatingActionButton) 
    findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", 
            Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new 
    ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new Frag1(), "Frag1");
    adapter.addFragment(new Frag2(), "Frag2);
    adapter.addFragment(new Frag3(), "Frag3");
    viewPager.setAdapter(adapter);
}

class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public ViewPagerAdapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position);
    }
}


}

希望这会有所帮助:)