atitit.標準時間格式 互相轉換 秒數 最佳實務,atitit最佳實務

來源:互聯網
上載者:User

atitit.標準時間格式 互相轉換 秒數 最佳實務,atitit最佳實務

atitit.標準時間格式 互相轉換 秒數 最佳實務 

 

例如00:01:19 轉換為秒數  79,,and互相轉換

 

一個思路是使用div 60 mod...不過麻煩的...

 

更好的方法是使用stamp

...

 

前台添加個日期,使用時間戳來計算...

 

作者:: 老哇的爪子 Attilax 艾龍,  EMAIL:1466519819@qq.com

轉載請註明來源: http://blog.csdn.net/attilax

 

 

public static void main(String[] args) throws ParseException {

// TODO Auto-generated method stub

String s="00:01:09";

int sec=str2secs(s);   //69

System.out.println(sec);

sec=79;  //00:01:19

System.out.println(secs2str(sec));

}

 

private static String secs2str(int sec) throws ParseException {

 String date="2014-01-01";

Date start= DateUtil.str2date_excpt(date+" 00:00:00", true); 

long endTimestamp = sec*1000+start.getTime();

Date end=new Date(endTimestamp);

String s=DateUtil.date2str(end, true);

String[] sa=s.split(" ");

return sa[1];

}

 

private static int str2secs(String s) throws ParseException {

 String date="2014-01-01";

 String full=date+" "+s;

Date dt= DateUtil.str2date_excpt(full, true);

Date dt2= DateUtil.str2date_excpt(date+" 00:00:00", true);

int i=DateUtil.getSecondInterval(dt2, dt);

 

return i;

}

 

參考

paip.日期時間操作以及時間戳記uapi php java python 總結 - attilax的專欄 - 部落格頻道 - CSDN.NET.htm


net下怎把毫秒數轉換成標準時間戳記

TimeSpan ts = new TimeSpan(1251790200000*10);
ts.Days表示對應的天數
ts.Hours表示對應的小時數,
依次推類.
注意:
// Parameters:
// ticks:
// A time period expressed in 100-nanosecond units.
public TimeSpan(long ticks);

你還可以用DateTime類型去Add這個類型的變數,得到加減後的時間.
 
把格林威治時間轉換成常用時間格式,以標準時間格式插入到資料庫

格林威治時間 和 時間格式 是一個概念嗎? 它們怎麼轉換啊,我也想知道。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.