HanG321 Blog
Be Shine, Be Smile, Be Wild
  • Home
  • Blog
    • 好文閱讀 readings
    • 生活記事 diary
    • 時事評論 commentary
    • 科技資訊 technology
    • 電腦編程 programming
    • 金融財經 finance
    • 音樂電影 music/movie
  • About

change srt time

February 28, 2007|Java, srt|電腦編程
Home » Blog » 電腦編程 » change srt time
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.StringTokenizer;
 
public class ChangeSrtTime {
  public static void main(String[] args) {
   File file = new File("C:\\The.departed.2of2.en.srt");
   String startTime, endTime;
   String result = "";
   int tunePara = 13;      //parameter for tuning
   ArrayList comp = new ArrayList();  //debug use
   boolean isDebug = false;    //set debug mode
   try {
    // Create a FileReader and then wrap it with BufferedReader.
    FileReader file_reader = new FileReader (file);
    BufferedReader buf_reader = new BufferedReader (file_reader);
    // Read each line of the file
    do {
     String line = buf_reader.readLine();
     if (line == null){
      break;
     }else if (line.startsWith("0") && (line.indexOf(":") == 2)){
      //e.g. 00:00:02,798 --> 00:00:06,296
      if(isDebug){ comp.add("org: " + line); }
      StringTokenizer st = new StringTokenizer(line, "-->");
      if (st.hasMoreTokens()){
       startTime = st.nextToken().trim();
       try {
        DateFormat formatter = new SimpleDateFormat("HH:mm:ss,SSS");
        Date date = (Date)formatter.parse(startTime);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.SECOND, tunePara);
        result = formatter.format(cal.getTime());
       } catch (ParseException e) {}
      }
      if(st.hasMoreTokens()) {
       endTime = st.nextToken().trim();
       try {
        DateFormat formatter = new SimpleDateFormat("HH:mm:ss,SSS");
        Date date = (Date)formatter.parse(endTime);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.SECOND, tunePara);
        result += " --> " + formatter.format(cal.getTime());
        if(isDebug){ comp.add("new: " + result);}
       } catch (ParseException e) {}
      }
      System.out.println(result);
     }else{
      System.out.println(line);
     }
    } while (true);
    buf_reader.close ();
   }
   catch (IOException e) {
    System.out.println ("IO exception =" + e );
   }
   if (isDebug){
    System.out.println("nnnn ==========debug console======== ");
    Iterator iterator = comp.iterator();
    while(iterator.hasNext()) {
     System.out.println(iterator.next());
    }
    System.out.println("n ==========END========= ");
   }
  }
}
 

February 28, 2007 user

Related Posts

  • JAVA_HOME of OpenJDK 1.7 on CentOS 7
    JAVA_HOME of OpenJDK 1.7 on CentOS 7June 7, 2015
  • Install Jenkins on Tomcat 7 (DSM)
    Install Jenkins on Tomcat 7 (DSM)August 18, 2014
  • AsyncWeb & load test
    AsyncWeb & load testJune 2, 2009

Popular Posts

  • Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)
    Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)June 8, 2015
  • assembly
    assemblyFebruary 11, 2006
  • 呢幾日個blogger 有問題….
    呢幾日個blogger 有問題….October 28, 2004
← 資訊科技發達的壞處
運氣 →

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.




最新文章 Recent Posts

  • Serverless Cloud Run Development: Challenge Lab
  • ionic 4: capacitor & pwa
  • Open file limit of tomcat and mysql in Linux server
  • avoid subquery in mysql update statement
  • hacktoberfest

最新留言 Recent Comments

  • admin on LikeCoin
  • Edmond on LikeCoin
  • John Smith on Install macOS High Sierra on VMware
  • admin on Install macOS High Sierra on VMware
  • nana on Install macOS High Sierra on VMware




熱門文章 Popular Posts

  • Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8)
    Install XPEnology (DSM) 5.1 on ESXi 6 (HP MicroServer Gen 8) June 8, 2015
  • 呢幾日個blogger 有問題….
    呢幾日個blogger 有問題…. October 28, 2004
  • assembly
    assembly February 11, 2006
  • 新工作
    新工作 January 6, 2009
  • 嫁人要嫁工程師
    嫁人要嫁工程師 April 27, 2006

標籤雲 Tag Cloud

CentOS Character chroot Cluster crash cryptography DD-WRT debug Domino DSM Dual Core DWA email ESXi GCP git google HylaFax IE Java Javascript JRE LikeCoin Linux log LotusScript mint MX MySQL nginx PKI PowerShell Qwiklabs srt telent VMware vpn vSphere WinXP wordpress XPEnology 專欄 網絡資訊 選股 風帆

日曆 Calendar

February 2007
M T W T F S S
  « Jan   Mar »  
 1234
567891011
12131415161718
19202122232425
262728  

Follow Me

Follow Us on RSSFollow Us on TwitterFollow Us on YouTube

文章存檔 Archives

Copyright © 2004-2021 hang321.net. All Rights Reserved