java 时间工具类

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
import java.io.File; 
import java.io.IOException; 
import java.net.URLEncoder; 
import java.text.DateFormat; 
import java.text.ParseException; 
import java.text.SimpleDateFormat; 
import java.util.Calendar; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import java.util.Locale; 
import java.util.regex.Matcher; 
import java.util.regex.Pattern; 
   
import javax.servlet.http.HttpServletRequest; 
   
import org.apache.commons.lang.StringUtils; 
import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 
   
import com.trs.gab.beans.AppPhrasseDataResult; 
import com.trs.gab.beans.DicDataModel; 
   
import sun.misc.UCEncoder; 
/**
 * 时间工具类
 *
 */ 
public class DateUtil { 
   
    /**
     * 返回数据库中以'YYYY-MM-DD HH24:MI:SS'格式表示当前时间的字符串
     * 用法:to_date(?,'YYYY-MM-DD HH24:MI:SS')
     * ?设置strNowtime
     * @return
     */ 
    public static String getNowTimeStr(){ 
        Calendar m_cal = Calendar.getInstance(); 
        String strNowtime = m_cal.get(Calendar.YEAR) + "-" 
                + (m_cal.get(Calendar.MONTH) + 1) + "-" 
                + m_cal.get(Calendar.DAY_OF_MONTH) + " " 
                + m_cal.get(Calendar.HOUR_OF_DAY) + ":" 
                + m_cal.get(Calendar.MINUTE) + ":" + m_cal.get(Calendar.SECOND); 
        return strNowtime; 
    
   
    /**
     * 获得当前时间,格式yyyy-MM-dd hh:mm:ss
     
     * @param format
     * @return
     */ 
    public static String getCurrentDateTime() { 
        return getCurrentDate("yyyy-MM-dd HH:mm:ss"); 
    
   
    /**
     * 获得当前时间,格式自定义
     
     * @param format
     * @return
     */ 
    public static String getCurrentDate(String format) { 
        Calendar day = Calendar.getInstance(); 
        day.add(Calendar.DATE, 0); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(day.getTime()); 
        return date; 
    
   
    /**
     * 获得昨天时间,格式自定义
     
     * @param format
     * @return
     */ 
    public static String getYesterdayDate(String format) { 
        Calendar day = Calendar.getInstance(); 
        day.add(Calendar.DATE, -1); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(day.getTime()); 
        return date; 
    
   
    /**
     * @param date1
     *            需要比较的时间 不能为空(null),需要正确的日期格式 ,如:2009-09-12
     * @param date2
     *            被比较的时间 为空(null)则为当前时间
     * @param stype
     *            返回值类型 0为多少天,1为多少个月,2为多少年
     * @return 举例: compareDate("2009-09-12", null, 0);//比较天
     *         compareDate("2009-09-12", null, 1);//比较月
     *         compareDate("2009-09-12", null, 2);//比较年
     */ 
    public static int compareDate(String startDay, String endDay, int stype) { 
        int n = 0
        String[] u = { "天", "月", "年" }; 
        String formatStyle = stype == 1 ? "yyyy-MM" : "yyyy-MM-dd"
   
        endDay = endDay == null ? getCurrentDate("yyyy-MM-dd") : endDay; 
   
        DateFormat df = new SimpleDateFormat(formatStyle); 
        Calendar c1 = Calendar.getInstance(); 
        Calendar c2 = Calendar.getInstance(); 
        try
            c1.setTime(df.parse(startDay)); 
            c2.setTime(df.parse(endDay)); 
        } catch (Exception e3) { 
            System.out.println("wrong occured"); 
        
        // List list = new ArrayList(); 
        while (!c1.after(c2)) { // 循环对比,直到相等,n 就是所要的结果 
            // list.add(df.format(c1.getTime())); // 这里可以把间隔的日期存到数组中 打印出来 
            n++; 
            if (stype == 1) { 
                c1.add(Calendar.MONTH, 1); // 比较月份,月份+1 
            } else
                c1.add(Calendar.DATE, 1); // 比较天数,日期+1 
            
        
        n = n - 1
        if (stype == 2) { 
            n = (int) n / 365
        
        // System.out.println(startDay+" -- "+endDay+" 相差多少"+u[stype]+":"+n); 
        return n; 
    
   
    /**
     * 判断时间是否符合时间格式
     */ 
    public static boolean isLegalDateString(String date, String dateFormat) { 
        if (date != null) { 
            java.text.SimpleDateFormat format = new java.text.SimpleDateFormat( 
                    dateFormat); 
            format.setLenient(false); 
            try
                format.format(format.parse(date)); 
            } catch (ParseException e) { 
                return false
            
            return true
        
        return false
    
   
    /**
     * 实现给定某日期,判断是星期几 date:必须yyyy-MM-dd格式
     */ 
    public static String getWeekday(String date) { 
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); 
        SimpleDateFormat sdw = new SimpleDateFormat("E"); 
        Date d = null
        try
            d = sd.parse(date); 
        } catch (ParseException e) { 
            e.printStackTrace(); 
        
        return sdw.format(d); 
    
   
    /**
     * 用来全局控制 上一周,本周,下一周的周数变化
     */ 
    private static int weeks = 0
   
    /**
     * 获得当前日期与本周一相差的天数
     */ 
    private static int getMondayPlus() { 
        Calendar cd = Calendar.getInstance(); 
        // 获得今天是一周的第几天,星期日是第一天,星期二是第二天...... 
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK); 
        if (dayOfWeek == 1
            return -6
        else 
            return 2 - dayOfWeek; 
    
   
    /**
     * 获得本周星期一的日期
     */ 
    public static String getCurrentMonday(String format) { 
        weeks = 0
        int mondayPlus = getMondayPlus(); 
        Calendar currentDate = Calendar.getInstance(); 
        currentDate.add(Calendar.DATE, mondayPlus); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(currentDate.getTime()); 
        return date; 
    
   
    /**
     * 获得上周星期一的日期
     */ 
    public static String getPreviousMonday(String format) { 
        weeks--; 
        int mondayPlus = getMondayPlus(); 
        Calendar currentDate = Calendar.getInstance(); 
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(currentDate.getTime()); 
        return date; 
    
   
    /**
     * 获得下周星期一的日期
     */ 
    public static String getNextMonday(String format) { 
        weeks++; 
        int mondayPlus = getMondayPlus(); 
        // GregorianCalendar currentDate = new GregorianCalendar(); 
        Calendar currentDate = Calendar.getInstance(); 
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(currentDate.getTime()); 
        return date; 
    
   
    /**
     * 获得相应周的周日的日期 此方法必须写在getCurrentMonday,getPreviousMonday或getNextMonday方法之后
     */ 
    public static String getSunday(String format) { 
        int mondayPlus = getMondayPlus(); 
        Calendar currentDate = Calendar.getInstance(); 
        currentDate.add(Calendar.DATE, mondayPlus + 7 * weeks + 6); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(currentDate.getTime()); 
        return date; 
    
   
    /**
     * method 将字符串类型的日期转换为一个timestamp(时间戳记java.sql.Timestamp)
     
     * @param dateString
     *            需要转换为timestamp的字符串
     * @return dataTime timestamp
     */ 
    public final static java.sql.Timestamp string2Time(String dateString) { 
        DateFormat dateFormat; 
        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);// 设定格式 
        dateFormat.setLenient(false); 
        java.util.Date date = null
        try
            date = dateFormat.parse(dateString); 
        } catch (ParseException e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        
        // java.sql.Timestamp dateTime = new java.sql.Timestamp(date.getTime()); 
        return new java.sql.Timestamp(date.getTime());// Timestamp类型,timeDate.getTime()返回一个long型 
    
   
    /**
     * method 将字符串类型的日期转换为一个Date(java.sql.Date)
     
     * @param dateString
     *            需要转换为Date的字符串
     * @return dataTime Date
     */ 
    public final static java.sql.Date string2Date(String dateString) { 
        DateFormat dateFormat; 
        dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); 
        dateFormat.setLenient(false); 
        java.util.Date date = null
        try
            date = dateFormat.parse(dateString); 
        } catch (ParseException e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        
        // java.sql.Date dateTime = new java.sql.Date(date.getTime());// sql类型 
        return new java.sql.Date(date.getTime()); 
    
   
    // 记录考勤, 记录迟到、早退时间 
    public static String getState() { 
        String state = "正常"
        DateFormat df = new SimpleDateFormat("HH:mm:ss"); 
        Date d = new Date(); 
        try
            Date d1 = df.parse("08:00:00"); 
            Date d2 = df.parse(df.format(d)); 
            Date d3 = df.parse("18:00:00"); 
   
            int t1 = (int) d1.getTime(); 
            int t2 = (int) d2.getTime(); 
            int t3 = (int) d3.getTime(); 
            if (t2 < t1) { 
   
                long between = (t1 - t2) / 1000;// 除以1000是为了转换成秒 
                long hour1 = between % (24 * 3600) / 3600
                long minute1 = between % 3600 / 60
   
                state = "迟到 :" + hour1 + "时" + minute1 + "分"
   
            } else if (t2 < t3) { 
                long between = (t3 - t2) / 1000;// 除以1000是为了转换成秒 
                long hour1 = between % (24 * 3600) / 3600
                long minute1 = between % 3600 / 60
                state = "早退 :" + hour1 + "时" + minute1 + "分"
            
            return state; 
        } catch (Exception e) { 
            return state; 
        
   
    
   
    /**
     * 数值型的时间改为字符串型时间
     
     * @param time
     * @return
     */ 
    public static String getTime(long time) { 
        try
            Date date = new Date(time); 
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//   
            String strdate = sdf.format(date); 
            return strdate; 
        } catch (Exception e) { 
            e.printStackTrace(); 
            return "0"
        
    
       
    /**
     * 传入"yyyy-MM-dd HH:mm:ss"格式字符串,传出从1970 年~~~  至dateString表示时刻之间的ms。
     * @return
     */ 
    public static long getTimeMillis(String dateString){ 
        long timeMillis = 0
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        try
            Date date= sdf.parse(dateString); 
            timeMillis = date.getTime(); 
        } catch (ParseException e) { 
        
        return timeMillis; 
    
       
    /**
     * 获得后N天的时间,格式自定义
     
     * @param format
     * @return
     */ 
    public static String getDelayDayDate(String format,int delay) { 
        Calendar day = Calendar.getInstance(); 
        day.add(Calendar.DATE, delay); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(day.getTime()); 
        return date; 
    
       
    /**
     * 获得后N小时的时间,格式自定义
     * @param format
     * @param delay
     * @return
     */ 
    public static String getDelayHourDate(String format,int delay){ 
        Calendar day = Calendar.getInstance(); 
        day.add(Calendar.HOUR, delay); 
        SimpleDateFormat sdf = new SimpleDateFormat(format);// "yyyy-MM-dd" 
        String date = sdf.format(day.getTime()); 
        return date; 
    
       
    /**
     * @param date1
     *            需要比较的时间 不能为空(null),需要正确的日期格式 ,如:2009-09-12 16:24
     * @param date2
     *            被比较的时间 为空(null)则为当前时间
     * @param stype 0为比较小时,1为比较分钟。
     * @return 
     */ 
    public static int compareTime(String startDay, String endDay,int stype) { 
        int n = 0
        String formatStyle = "yyyy-MM-dd HH:mm"
   
        endDay = endDay == null ? getCurrentDate("yyyy-MM-dd HH:mm") : endDay; 
   
        DateFormat df = new SimpleDateFormat(formatStyle); 
        Calendar c1 = Calendar.getInstance(); 
        Calendar c2 = Calendar.getInstance(); 
        try
            c1.setTime(df.parse(startDay)); 
            c2.setTime(df.parse(endDay)); 
        } catch (Exception e3) { 
            System.out.println("wrong occured"); 
        
        // List list = new ArrayList(); 
        while (!c1.after(c2)) { // 循环对比,直到相等,n 就是所要的结果 
            // list.add(df.format(c1.getTime())); // 这里可以把间隔的日期存到数组中 打印出来 
            n++; 
            if(stype == 0){ 
                c1.add(Calendar.HOUR, 1); // 比较月份,月份+1 
            }else
                c1.add(Calendar.MINUTE, 1); // 比较月份,月份+1 
            
        
        n = n - 1
        return n; 
    
    /**
     * 获取词典(牛津英汉词典)音标的信息
     */ 
    public static String getYin(String content) 
    
        String result=""
        String reg="<font color=([\"'])#F17D1F([\"']) size=4>(?:.*?)</font>"
        //String str="<td class=\"longtd\" title=\"VRBZ3\">VRBZ3</td>"; 
        String str="<font color=red>china</font><font color=green>china</font>"
        Pattern p=Pattern.compile(reg); 
        Matcher m=p.matcher(content); 
        int i=1
        while(m.find()){ 
            System.out.println(m.group(0)); 
            result=result+"<br>"+"<font color=#F17D1F>"+i+"</font>"+m.group(0).replaceAll("size=4", "style=\"font-family:Arial Unicode Ms\";"); 
            i++; 
        
        if(i==2
        {   
            String r="<font color=#F17D1F>"
            int x=result.indexOf(r); 
            result=result.substring(x+r.length()+1); 
        
        return result; 
    
    /**
     * 获取词典(字典)中的信息、
     */ 
    public static String getFont(String content) 
    
        String result=""
        String reg="(?:.*?)<br>"
        //String str="<td class=\"longtd\" title=\"VRBZ3\">VRBZ3</td>"; 
        String str="你<br>nǐ<br>称对方,多称指一个人,有时也指称若干人:你厂。你方。<br>泛指任何人:你死我活。<br>您<br><br>笔画数:7;<br>部首:亻;<br>笔顺编号:3235234<br><br><br>"
        Pattern p=Pattern.compile(reg); 
        Matcher m=p.matcher(content); 
        int i=1
        while(m.find()){ 
            System.out.println(m.group(0)); 
            if(!m.group(0).equals("<br>")) 
            
            result=result+i+"、   "+m.group(0); 
            i++; 
            
               
        
           
        return result; 
    
    public static String getDemo(String color,String content) 
    
        String result=""
        String reg="<font color="+color+">(?:.*?)</font>"
        //String str="<td class=\"longtd\" title=\"VRBZ3\">VRBZ3</td>"; 
        String str="<font color=red>china</font><font color=green>china</font>"
        Pattern p=Pattern.compile(reg); 
        Matcher m=p.matcher(content); 
           
        if(color.equals("blue")) 
        
            int i=1
            while(m.find()){ 
                System.out.println(m.group(0)); 
                result=result+"<br> <font color=blue>"+i+" </font>"+m.group(0).replaceAll("size=4", ""); 
                i++; 
            
        
        else 
        {  
               
               
            while(m.find()){ 
                System.out.println(m.group(0)); 
                result=result+"<br>"+m.group(0).replaceAll("size=4", ""); 
               
            
               
        
        return result; 
    
    public static String getUse(String content) 
    
        String result=""
        String reg="</font>(?:.*?)<br>"
        //String str="<td class=\"longtd\" title=\"VRBZ3\">VRBZ3</td>"; 
        String str="<font color=red>china</font><font color=green>china</font>"
        Pattern p=Pattern.compile(reg); 
        Matcher m=p.matcher(content); 
           
           
            while(m.find()){ 
                System.out.println(m.group(0)); 
                result=result+m.group(0).replaceAll("size=4", ""); 
                   
            
           
           
        return result; 
    
    public static String[] getContent(String content,String prefex) 
    
        String result[]=new String[3]; 
        String reg=prefex+"(?:.*?)</div>"
        //String str="<td class=\"longtd\" title=\"VRBZ3\">VRBZ3</td>"; 
        String str="<font color=red>china</font><font color=green>china</font>"
        Pattern p=Pattern.compile(reg); 
        Matcher m=p.matcher(content); 
           
        int count=0
            while(m.find()){ 
                if(count<3
                
                    result[count]=m.group(0); 
                
                count++; 
            
           
        return result; 
    
    public static boolean getContent(String content,String prefex,String reg) 
    
        boolean result=false
        Pattern p=Pattern.compile(reg); 
        Matcher m=p.matcher(content); 
           
           
            while(m.find()){ 
                   
                result=true
            
            return result; 
    
    public static String getC(String content,String prefex) 
    
        System.out.println("未处理的t内容"+content); 
        int start=content.indexOf(prefex); 
        String result=""
        if(start!=-1
        
        result=content.substring(start, content.length()-1); 
        return result.replaceAll("</div>","")+"</div>"
        
        else 
        
            result=content; 
            return result; 
        
           
           
           
    
    public static String getContent(String content) 
    
        String s_content[]=new String[2]; 
        for(int i=0;i<2;i++) 
        
            s_content[i]=content; 
        
        String v=getContent(s_content[0],"<div id=v>")[0]; 
           
        String c=getContent(s_content[1],"<div id=c>")[0]; 
        if(!getContent(c, "<div id=c>", "[\u4E00-\u9FA5]")) 
        
            c=getC(s_content[1],"<div id=c>"); 
        
        return c+v; 
    
       
    public static String replaceTag(String content) 
    
        return content.replaceAll("<br>", " ").replaceAll("bword://", "").replaceAll("\\\\n", "").replaceAll("<img.*>.*</img>","").replaceAll("<img.*/>",""); 
    
     /** 
      * 获取现在时间 
      * @return返回字符串格式 yyyy-MM-dd HH:mm:ss 
      */  
     public static String getStringDate() {   
      Date currentTime = new Date();   
      SimpleDateFormat formatter = new SimpleDateFormat("M月d日");   
      String dateString = formatter.format(currentTime);   
      return dateString;   
     
    public static String getNum(String content) 
    
        String result=""
        String reg="(?:.*?)。"
           
        //String str="<td class=\"longtd\" title=\"VRBZ3\">VRBZ3</td>"; 
        String str="(1)在体积、面积、数量、力量、强度等方面不及一般的或不及比较的对象(跟‘大’相对):~河|鞋~了点儿|我比你~一岁|声音太~。(2)短时间地:~坐|~住。(3)排行最末的:~儿子|他是我的~弟弟。(4)年纪小的人:一家大~|上有老,下有~。(5)指妾①。(6)谦辞,称自己或与自己有关的人或事物:~弟|~店。 …小白菜@(~ "
        Pattern p=Pattern.compile(reg); 
        Matcher m=p.matcher(content); 
           
           
            while(m.find()){ 
            if(m.group(0).length()>3
            
                System.out.println(m.group(0)); 
                result=result+m.group(0)+"<br>"
             
            else 
            
                result=content; 
            
            
        if(result.length()==0
        
            result=content; 
        
           
        return result; 
    
    /**
     * @param args
     * @return 
     * @return 
     */ 
    public static String getContentSource(String contentSource,String tag,String tagId,int wordSize) 
    
        Document doc; 
        String linkText=""
        //System.out.println("未处理的文本内容:"+contentSource); 
        try
            doc = Jsoup.parse(contentSource); 
   
            Element content = doc.getElementById(tagId); 
            if(content!=null){ 
            Elements texts = content.select(tag + "[id=" + tagId + "]"); 
            for (Element link : texts) { 
   
                linkText = linkText + link.text(); 
            
            
            else 
            
                Element t = doc.getElementById("t"); 
                if(t!=null){ 
                Elements texts = t.select("div[id=t]"); 
                for (Element link : texts) { 
   
                    linkText = linkText + link.text(); 
                
                
                else 
                
                    linkText=contentSource; 
                
            
        } catch (Exception e) { 
   
            e.printStackTrace(); 
        
        //System.out.println("得到的文本内容:"+linkText); 
        if(linkText.length()>300
        
            linkText=linkText.substring(0, wordSize)+"..."
        
        return linkText; 
    
       
    public static String getContentText(String contentSource,String tag,String tagId) 
    
        Document doc; 
        String linkText=""
        //System.out.println("未处理的文本内容:"+contentSource); 
        try
            doc = Jsoup.parse(contentSource); 
   
            Element content = doc.getElementById(tagId); 
            if(content!=null){ 
            Elements texts = content.select(tag + "[id=" + tagId + "]"); 
            for (Element link : texts) { 
   
                linkText = linkText + link.text(); 
            
            
               
        } catch (Exception e) { 
   
            e.printStackTrace(); 
        
        //System.out.println("得到的文本内容:"+linkText); 
        return linkText; 
    
    /**
     * 得到div id=m的内容
     * @param contentSource
     * @param tag
     * @param tagId
     * @return
     */ 
    public static String getContentSourceOfm(String contentSource,String tag,String tagId) 
    
        Document doc; 
        String linkText=""
        //System.out.println("未处理的文本内容:"+contentSource); 
        try
            doc = Jsoup.parse(contentSource); 
   
            Element content = doc.getElementById(tagId); 
            if(content!=null){ 
            Elements texts = content.select(tag + "[id=" + tagId + "]"); 
            for (Element link : texts) { 
   
                linkText = linkText + link.text(); 
            
            
            else 
            
                Element t = doc.getElementById("t"); 
                if(t!=null){ 
                Elements texts = t.select("div[id=t]"); 
                for (Element link : texts) { 
   
                    linkText = linkText + link.text(); 
                
                
                else 
                
                    linkText=contentSource; 
                
            
        } catch (Exception e) { 
   
            e.printStackTrace(); 
        
        //System.out.println("得到的文本内容:"+linkText); 
        if(linkText.length()>300
        
            linkText=linkText.substring(0, 300)+"..."
        
        return linkText; 
    
    public static boolean isHasRelativeWordlink(String content,String tag) 
    
        if(content.contains(tag)) 
        
            return true
        
        else 
        
            return false
        
    
    /**
     * 得到相关词条的解释
     * @param content
     * @param request
     * @param tag
     * @return
     */ 
    public static String getRelativeWordlink(String content,HttpServletRequest request,String tag) 
    
        String param[]=content.split(tag); 
        //URLEncoder encoder=null; 
           
       
        content="参考词条:<a href="+request.getContextPath()+"/baikeSearchRelative.trs?searchWord="+param[1].replaceAll("\\\\n", "")+"  target=\"_blank\">"+param[1].replaceAll("\\\\n", "")+"</a>"
        return content; 
    
       
    /**
     * 得到相关词条的解释
     * @param content
     * @param request
     * @param tag
     * @return
     */ 
    public static DicDataModel getRelativeWordContent(String content,String tag,int type) 
    
           
           
        String param[]=content.split(tag); 
        //URLEncoder encoder=null; 
        DicDataModel dataModel=null
           
        AppPhrasseDataResult appPhrasseDataResult=null
           
        appPhrasseDataResult=new AppPhrasseDataResult(); 
           
        try
            dataModel=appPhrasseDataResult.getBaikeInfo("TB_BAIKE", "name="+param[1].replaceAll("\\\\n", "")); 
        } catch (Exception e) { 
               
            e.printStackTrace(); 
        
        if(type==0
        
            dataModel.setContent(DateUtil.getContentSource(dataModel.getContent(), "", "c",300),new Boolean("true")); 
        
        else 
        
   
            dataModel.setContent(dataModel.getContent(),new Boolean("true")); 
               
        
        return dataModel; 
    
    /**
     * 将相关词条添加到字符串数组中
     * @param contentSource
     * @param request
     * @return
     */ 
    public static String[] getRelativeWordlink(String contentSource,HttpServletRequest request) 
    {Document doc; 
    String relativeWord[]=null
    int count=0
    try
        doc = Jsoup.parse(contentSource); 
   
        Element content = doc.getElementById("m"); 
        //Elements links = content.getElementsByTag("td"); 
        if(content!=null){ 
        Elements links = content.select("a"); 
        relativeWord=new String[links.size()]; 
        for (Element link : links) { 
            
          String linkText = link.text(); 
   
            if(linkText.contains("@")) 
            
              relativeWord[count]=linkText; 
            
            count++; 
        
        
    } catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
    
        return relativeWord; 
    
    /**
     * 将相关词条的细缆页链接加上
     * @param content
     * @param relativeWord
     * @param request
     * @return
     */ 
    public static String replaceRelativeWord(String content,String relativeWord[],HttpServletRequest request) 
    
        for(int i=0;i<relativeWord.length;i++) 
        {   String c=relativeWord[i]; 
            if(StringUtils.isNotEmpty(c)) 
            
            String r=relativeWord[i].substring(1); 
            content=content.replaceFirst(r, request.getContextPath()+"/baikeSearchRelative.trs?searchWord="+r); 
            
            
        return content; 
    
    /**
     * 得到词条的目录链接:
     * 默认取前5条链接
     * @param content
     * @return
     */ 
    public static String getLink(String contentSource, String linkContent,int count,String tag) { 
        Document doc; 
        String linkText = ""
        try
            doc = Jsoup.parse(contentSource); 
   
            Element content = doc.getElementById(tag); 
            if(content!=null){ 
            Elements links = content.select("p"); 
               
                int i=1
                for (Element link : links) { 
                    String href=getChildlink(link.outerHtml()); 
                    if(StringUtils.isNotEmpty(href)) 
                    
                   linkText = linkText +"<p>"+href+"</p>"
                    
                   if(i==count) 
                    
                        break
                    
   
                    i++; 
                
                /*if(i<count)
                {
                    linkText = linkText+getLinkOfm(linkContent, count-i,"m");
                }*/ 
            
               
            else 
            
                linkText=contentSource; 
            
        } catch (Exception e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        
        return linkText; 
    
    /**
     * 链接的数量不足时增加m标签的内容
     * @param contentSource
     * @param linkContent
     * @param count
     * @param tag
     * @return
     */ 
    public static String getLinkOfm(String linkContent,int count,String tag) { 
        Document doc; 
        String linkText = ""
        try
            doc = Jsoup.parse(linkContent); 
   
            Element content = doc.getElementById(tag); 
            if(content!=null){ 
            Elements links = content.select("p"); 
               
                int i=0
                for (Element link : links) { 
                   linkText = linkText +"<p>"+ getChildlink(link.outerHtml())+"</p>"
                    if(i==count) 
                    
                        break
                    
   
                    i++; 
                
                   
            
               
            else 
            
                linkText=linkContent; 
            
        } catch (Exception e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        
        return linkText; 
    
    /**
     * 获取链接的子链接的第一个链接
     * @param contentSource
     * @return
     */ 
    public static String getChildlink(String contentSource) { 
   
        Document doc; 
        String linkText = null
        try
            doc = Jsoup.parse(contentSource); 
   
            Elements links = doc.select("a"); 
            if (links != null) { 
                int i = 0
                for (Element link : links) { 
                    if (i == 0) { 
                        linkText = link.outerHtml(); 
                    
                    i++; 
                
            } else
                linkText = contentSource; 
            
        } catch (Exception e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        
        return linkText; 
    
    public static int getNowTime(int type){ 
        Calendar m_cal = Calendar.getInstance(); 
        if(type==1
        
            return m_cal.get(Calendar.MONTH)+1
        
        else 
            return m_cal.get(Calendar.DAY_OF_MONTH); 
    
    public static void main(String[] args) { 
   
    System.out.println(getContentText("<div id=t><p></div>\n","div","t"));     
    
   
}