如何在golang中使用日期时间添加秒

时间:2018-07-19 12:06:15

标签: go

我有一个日期?php require_once "Mobile_Detect.php"; //////////////////////////// //// PAYMENT REDIRECTION FUNCTION //////////////////////////// function my_save_post_iq( $post_id ) { debug_to_console( "save post function fired" ); $billplzApi = get_field('iq_secret_key', 'option'); $billplzId = get_field('iq_collection_id', 'option'); // bail early if not a donation post if( get_post_type($post_id) !== 'qurban' ) { return; } // bail early if editing in admin if( is_admin() ) { return; } $post = get_post( $post_id); $jumlah_bayaran_iq = get_field('jumlah_bayaran', $post_id); //check & update user device type $detect = new Mobile_Detect; if($detect->isMobile()){ update_field('devices', 'mobile' , $post); } else { update_field('devices', 'desktop', $post); } $name = get_field('nama_penuh', $post); $email = get_field('emel', $post); $mobile = get_field('nombor_telefon', $post); $bank = get_field('bank', $post); $billplz_data = array( 'amount' => $jumlah_bayaran_iq * 100, 'name' => $name, 'mobile' => $mobile, 'email' => $email, 'collection_id' => $billplzId, 'deliver' => false, 'reference_1_label' => 'Bank Code', 'reference_1' => $bank, 'reference_2_label' => 'Post ID', 'reference_2' => $post_id, 'description' => 'xxx', 'redirect_url' => home_url('qurbanv2/paymentredirectv2'), 'callback_url' => home_url('paymentcallback') ); $process = curl_init('https://www.billplz.com/api/v3/bills/'); curl_setopt($process, CURLOPT_HEADER, 0); curl_setopt($process, CURLOPT_USERPWD, $billplzApi . ":"); curl_setopt($process, CURLOPT_TIMEOUT, 30); curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($billplz_data)); $return = curl_exec($process); curl_close($process); $arr = json_decode($return, true); $billplz_url = $arr['url']; $billplz_id = $arr['id']; //update payment status update_field('billplz_iq', $billplz_id , $post); //$hzpost_name = array( // 'ID' = $post, // 'post_name' = $billplz_url //); // //wp_update_post($hzpost_name); header('Location: '. $billplz_url . '?auto_submit=true'); exit(); } add_action('save_post', 'my_save_post_iq', 10, 1); 和一个秒2018-07-10 09:35:39。 现在,我想给DateTime添加秒数。

所以最终结果应该是10

我尝试如下:-

2018-07-10 09:35:49

1 个答案:

答案 0 :(得分:0)

假设您的日期类型为Time

time.Add(10 * time.Second)

编辑:在您的情况下,似乎您只需要将日期用引号引起来即可,将其设为字符串:

Mydate := "2018-07-10 09:35:39"

从Parse()检查错误可能很有用