在Google Apps脚本上,我正在尝试将数据的时间戳修正为常规日期(月/日/年)。
这是我在数据集的特定列上获得的日期示例:
public static class TypingDialogFragment extends DialogFragment {
EditText cmdLine;
static MainActivity parentActivity;
static ThreadConnected cmdThreadConnected;
static int a=0;
static int type1=0;
static int type2=0;
static int run_voice=0;
static int run_voice1=0;
static byte[] memory_freq="100".getBytes();
static byte[] gain_rf="42".getBytes();
static byte[] gain_if="47".getBytes();
static byte[] gain_bb="0".getBytes();
byte[] NewLine = "\n".getBytes();
byte[] kill="killall python".getBytes();
byte[] run_emetteur="DISPLAY=:0 python emetteur.py --freq ".getBytes();
byte[] run_receiver="DISPLAY=:0 python receiver.py --freq ".getBytes();
byte[] end_command = "&".getBytes();
byte[] freq_Mhz = "e6 ".getBytes();
byte[] RF_text=" --RF ".getBytes();
byte[] IF_text=" --IF ".getBytes();
byte[] BB_text=" --BB ".getBytes();
// MediaPlayer
private String OUTPUT_FILE;
private boolean stopped = false;
MediaPlayer mediaPlayer;
MediaRecorder mediaRecorder;
File outFile;
// Image button
ImageButton send_voice;
Chronometer myChrono;
ProgressBar progressBar;
Audio record_song; // My VARIABLE -------------------------------------------------------------------------------------------
static TypingDialogFragment newInstance(MainActivity parent, ThreadConnected thread, int type){
type1=type;
parentActivity = parent;
cmdThreadConnected = thread;
TypingDialogFragment f = new TypingDialogFragment();
return f;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().setTitle("Cmd Line");
getDialog().setCanceledOnTouchOutside(false);
final View typingDialogView = inflater.inflate(R.layout.typing_layout, container, false);
ImageView imgCleaarCmd = (ImageView)typingDialogView.findViewById(R.id.clearcmd);
// Audio
/* OUTPUT_FILE= Environment.getExternalStorageDirectory()+ "/audiorecord.wav";
outFile=new File (OUTPUT_FILE);*/
record_song=new Audio(); // ERROR HERE --------------------------------------------------------------------------------
cmdLine = (EditText)typingDialogView.findViewById(R.id.cmdline);
myChrono=(Chronometer) getActivity().findViewById(R.id.chronometer1);
send_voice=(ImageButton) getActivity().findViewById(R.id.send_voice1);
progressBar=(ProgressBar) getActivity().findViewById(R.id.progressBar1);
Button bouton1 = (Button)typingDialogView.findViewById(R.id.button1);
Button bouton2=(Button)typingDialogView.findViewById(R.id.button2);
Button bouton3 = (Button)typingDialogView.findViewById(R.id.button3);
Button bouton4 = (Button)typingDialogView.findViewById(R.id.button4);
final ImageButton send_voice=(ImageButton)getActivity().findViewById(R.id.send_voice1);
imgCleaarCmd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
if(type1==1)
{
bouton1.setText("STOP");
bouton2.setText("OFF");
bouton3.setText("Reset");
bouton4.setText("Enter");
}
if(type1==2)
{
bouton1.setText("TX");
bouton2.setText("RX");
bouton3.setText("Clear");
bouton4.setText("Enter");
}
if(type1==3)
{
bouton1.setText("Gain RF");
bouton2.setText("Gain IF");
bouton3.setText("Gain BB");
bouton4.setText("Enter");
}
bouton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type1==1)
{
cmdLine.setText("killall python");
}
if (type1==2)
{
cmdLine.setHint("// Partie Emission");
a=1;
}
if (type1==3)
{
type2=1;
cmdLine.setHint("// Gain RF");
}
}
});
bouton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type1==1)
{
cmdLine.setText("sudo poweroff");
}
if (type1==2)
{
cmdLine.setHint("// Partie Reception");
a=2;
}
if (type1==3)
{
byte[] bytesToSend = cmdLine.getText().toString().getBytes();
if (bytesToSend!=null)
{
type2=2;
cmdLine.setHint("// Gain IF");
}
}
}
});
bouton3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (type1==1)
{
cmdLine.setText("sudo reboot");
a=1;
}
if (type1==2)
{
body.setText("");
}
if (type1==3)
{
byte[] bytesToSend = cmdLine.getText().toString().getBytes();
if (bytesToSend!=null)
{
type2=3;
cmdLine.setHint("// Gain BB");
}
}
}
});
bouton4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(cmdThreadConnected!=null){
if (type1==1)
// Command terminal
{
byte[] bytesToSend = cmdLine.getText().toString().getBytes();
cmdThreadConnected.write(bytesToSend);
byte[] NewLine = "\n".getBytes();
cmdThreadConnected.write(NewLine);
}
if (type1==2) // FREQUENCE lancement de la partie réception ou émission
{
if (a==1)
{
byte[] bytesToSend = cmdLine.getText().toString().getBytes();
memory_freq=bytesToSend;
cmdThreadConnected.write(kill);
cmdThreadConnected.write(NewLine);
cmdThreadConnected.write(run_emetteur);
cmdThreadConnected.write(memory_freq);
cmdThreadConnected.write(freq_Mhz);
cmdThreadConnected.write(RF_text);
cmdThreadConnected.write(gain_rf);
cmdThreadConnected.write(IF_text);
cmdThreadConnected.write(gain_if);
cmdThreadConnected.write(BB_text);
cmdThreadConnected.write(gain_bb);
cmdThreadConnected.write(end_command);
cmdThreadConnected.write(NewLine);
}
if (a==2)
{
byte[] bytesToSend = cmdLine.getText().toString().getBytes();
memory_freq=bytesToSend;
cmdThreadConnected.write(kill);
cmdThreadConnected.write(NewLine);
cmdThreadConnected.write(run_receiver);
cmdThreadConnected.write(memory_freq);
cmdThreadConnected.write(freq_Mhz);
cmdThreadConnected.write(RF_text);
cmdThreadConnected.write(gain_rf);
cmdThreadConnected.write(IF_text);
cmdThreadConnected.write(gain_if);
cmdThreadConnected.write(BB_text);
cmdThreadConnected.write(gain_bb);
cmdThreadConnected.write(end_command);
cmdThreadConnected.write(NewLine);
}
}
if(type1==3)
{
byte[] bytesToSend = cmdLine.getText().toString().getBytes();
if (type2==1)gain_rf=bytesToSend;
if (type2==2)gain_if=bytesToSend;
if (type2==3)gain_bb=bytesToSend;
dismiss();
}
}
}
});
send_voice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (run_voice==0)
{
try{
beginRecording();
send_voice.setColorFilter(Color.RED);
progressBar.setVisibility(View.VISIBLE);
myChrono.setBase(SystemClock.elapsedRealtime());
myChrono.start();
cmdThreadConnected.write(kill);
cmdThreadConnected.write(NewLine);
cmdThreadConnected.write(run_emetteur);
cmdThreadConnected.write(memory_freq);
cmdThreadConnected.write(freq_Mhz);
cmdThreadConnected.write(RF_text);
cmdThreadConnected.write(gain_rf);
cmdThreadConnected.write(IF_text);
cmdThreadConnected.write(gain_if);
cmdThreadConnected.write(BB_text);
cmdThreadConnected.write(gain_bb);
cmdThreadConnected.write(end_command);
cmdThreadConnected.write(NewLine);
}catch (IOException ex)
{
// if not working
}
run_voice1=1;
}
if (run_voice==1)
{
stopRecording();
send_voice.setColorFilter(Color.BLACK);
progressBar.setVisibility(View.INVISIBLE);
myChrono.stop();
cmdThreadConnected.write(kill);
cmdThreadConnected.write(NewLine);
cmdThreadConnected.write(run_receiver);
cmdThreadConnected.write(memory_freq);
cmdThreadConnected.write(freq_Mhz);
cmdThreadConnected.write(RF_text);
cmdThreadConnected.write(gain_rf);
cmdThreadConnected.write(IF_text);
cmdThreadConnected.write(gain_if);
cmdThreadConnected.write(BB_text);
cmdThreadConnected.write(gain_bb);
cmdThreadConnected.write(end_command);
cmdThreadConnected.write(NewLine);
run_voice1=0;
}
run_voice=run_voice1;
}
private void ditchMediaplayer()
{
if (mediaRecorder!=null)mediaRecorder.release();
try
{
mediaPlayer.release();
}catch (Exception e)
{
e.printStackTrace();
}
}
private void beginRecording()throws IOException
{
/* ditchMediaplayer();
if (outFile.exists())
{
outFile.delete();
}
mediaRecorder=new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile(OUTPUT_FILE);
mediaRecorder.prepare();
mediaRecorder.start();*/
record_song.run();
}
private void stopRecording()
{
/* if (mediaRecorder !=null)
{
mediaRecorder.stop();
mediaPlayer.release();
mediaPlayer = null;
}*/
record_song.close();
}
});
return typingDialogView;
}
}
我一直在尝试将年,月,日子串联起来,以便按照我想要的方式将它们连接起来,但没有成功。 (在JS上仍然是noobie)
[[2017-06-19T09:53:12+0200], [2017-06-19T10:08:14+0200], [2017-06-19T10:08:55+0200], [2017-06-19T10:14:48+0200], [2017-06-19T10:19:35+0200], [2017-06-19T10:30:44+0200], [2017-06-19T10:32:51+0200], [2017-06-19T10:44:28+0200]]
有人可以帮助我吗?
答案 0 :(得分:0)
您可以使用split
获取部分日期字符串:
function formatDates() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('ImportData');
var dataRange = sheet.getRange(2, 1, sheet.getLastRow()-1, 1);
var data = dataRange.getValues();
for (var i = 0; i < data.length; i++)
{
// get date
var date = data[i][0].split('T')[0];
// get date parts
var dateParts = date.split('-');
// get date in format MM/dd/yyyy
var newDate = dateParts[1]+'/'+dateParts[2]+'/'+dateParts[0];
// rewrite date in data array
data[i] = [newDate];
}
// write new values to sheet
dataRange.setValues(data);
}