Java window Program string time to Timestamp

Source: Internet
Author: User
Tags gettext log4j

Pom.xml file:

? xml version= "1.0" encoding= "UTF-8"? ><project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://ww W.w3.org/2001/xmlschema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ Xsd/maven-4.0.0.xsd "> <parent> <artifactId>base</artifactId> &LT;GROUPID&GT;COM.BIGD ata</groupid> <version>1.0</version> </parent> <modelversion>4.0.0</modelver sion> <artifactId>base-tools</artifactId> <dependencies> <dependency> & Lt;groupid>commons-lang</groupid> <artifactId>commons-lang</artifactId> <ver sion>2.6</version> </dependency> <dependency> &LT;GROUPID&GT;ORG.ECLIPSE.SWT </groupId> <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId> <version   >4.3</version>     </dependency> <dependency> <artifactId>log4j</artifactId> <gr oupid>log4j</groupid> <version>1.2.17</version> </dependency> <depe Ndency> <groupId>org.slf4j</groupId> &LT;ARTIFACTID&GT;SLF4J-LOG4J12&LT;/ARTIFACTID&G            T                    <version>${slf4j.version}</version> <exclusions> <exclusion>                <artifactId>log4j</artifactId> <groupId>log4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <grou Pid>org.eclipse.swt</groupid> <artifactId>swing2swt</artifactId> <version&gt ;1.0</version> </dependency> <dependency> <groupid>commons-io</groupid      >      <artifactId>commons-io</artifactId> <version>2.4</version> </dependency > <dependency> <groupId>commons-collections</groupId> <artifactId> commons-collections</artifactid> <version>3.2.1</version> </dependency> </ dependencies> <build> <plugins> <plugin> <groupid>org.apach E.maven.plugins</groupid> <artifactId>maven-shade-plugin</artifactId> <                        Version>2.4.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade&                            Lt;/goal> </goals> <configuration>   <transformers>                             <transformer implementation= "Org.apache.maven.plugins.shade.resource.ManifestResourceTrans                                Former "> <mainClass>com.hikvision.cods.ui.DateFormatMainUI</mainClass>                        </transformer> </transformers> </configuration> </execution> </executions> </plugin&gt        ; </plugins> </build></project>

  

Class:

Import Com.hikvision.cods.util.fontutils;import java.awt.dimension;import java.awt.toolkit;import java.util.Date; Import Java.util.properties;import Org.apache.commons.lang.stringutils;import Org.apache.commons.lang.math.numberutils;import Org.apache.log4j.propertyconfigurator;import Org.eclipse.swt.events.focusevent;import Org.eclipse.swt.events.focuslistener;import Org.eclipse.swt.events.mouseevent;import Org.eclipse.swt.events.mouselistener;import Org.eclipse.swt.events.shelladapter;import Org.eclipse.swt.events.shellevent;import Org.eclipse.swt.layout.griddata;import Org.eclipse.swt.layout.gridlayout;import Org.eclipse.swt.widgets.composite;import Org.eclipse.swt.widgets.display;import Org.eclipse.swt.widgets.Group; Import Org.eclipse.swt.widgets.label;import Org.eclipse.swt.widgets.messagebox;import Org.eclipse.swt.widgets.shell;import Org.eclipse.swt.widgets.text;import Org.slf4j.logger;import Org.slf4j.loggerfactory;import Swing2swt.layout.borderlayout;public class Dateformatmainui{protected static final Logger Logger = Loggerfactory.getlogger (Dateformatmainui.class);    Private static Volatile Boolean running = true;    public static final Display display = Display.getdefault ();    public static final Shell shell = new Shell (192); public static void Main (string[] args) {runtime.getruntime (). Addshutdownhook (New Thread () {p                ublic void Run () {DateFormatMainUI.logger.info ("Perfmainui closed!");                    Synchronized (dateformatmainui.class) {dateformatmainui.running = false;                DateFormatMainUI.class.notifyAll ();        }            }        });        Dateformatmainui window = new Dateformatmainui ();        Window.configlog4j ();        window.open ();                    Synchronized (Dateformatmainui.class) {while (running) {try {                DateFormatMainUI.class.wait ();     }           catch (Throwable localthrowable) {}}}} protected void Open () {Shell.setsi        Ze (500, 130);        Shell.settext ("Date format conversion tool");        Shell.setlayout (New BorderLayout (0, 0));        Composite subcomposite = new Composite (shell, 0);        Subcomposite.setlayout (New BorderLayout (5, 5));        Loadmainpanel (Subcomposite);        Dimension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();        int width = math.min (Shell.getsize (). x, Screensize.width);        int height = math.min (shell.getsize (). Y, Screensize.height);        int LocX = (screensize.width-width)/2;        int locy = (screensize.height-height)/2;        Shell.setlocation (LocX, locy);        Shell.open ();        Shell.layout ();                Shell.addshelllistener (New Shelladapter () {public void shellclosed (Shellevent e) {                MessageBox MessageBox = New MessageBox (Dateformatmainui.shell, 196); Messagebox.settext ("Confirm");                Messagebox.setmessage ("Are you sure you want to exit?");                int message = Messagebox.open (); if ((e.doit = message = =)? 1:0)! = 0) {DateFormatMainUI.logger.info ("+++++++++++                    +++++++++++++++++++++");                System.exit (0);        }            }        });            while (!shell.isdisposed ()) {if (!display.readanddispatch ()) {display.sleep ();    }} display.dispose ();        } protected void Loadmainpanel (Composite parent) {Composite maincenter = new Composite (parent, 0);        Maincenter.setlayoutdata ("Center");        GridLayout gl_maincenter = new GridLayout (1, false);        gl_maincenter.marginwidth = 0;        gl_maincenter.marginheight = 0;        gl_maincenter.horizontalspacing = 0;        gl_maincenter.verticalspacing = 0;        Maincenter.setlayout (Gl_maincenter);        Group Detailgroup = new Group (maincenter, 0); Detailgroup.Setlayoutdata (New Griddata (4, 4, True, True, 1, 1));        Detailgroup.setlayout (New GridLayout (5, false));        Generatetextlabel (Detailgroup, "date character:");        Final Text textdatestr = Generatetext (Detailgroup, "", "datestr");        Generatespliterlabel (Detailgroup);        Generatetextlabel (Detailgroup, "Date value:");        Final Text textdatenum = Generatetext (Detailgroup, "", "Datenum");        Generatespliterlabel (Detailgroup);                Textdatestr.addfocuslistener (New Focuslistener () {public void Focuslost (FocusEvent arg0) {                Textdatestr.clearselection (); Date date = Dateformatutils.todate (Textdatestr.gettext (), "Yyyy-mm-dd HH:mm:ss.                SSS ");            Textdatenum.settext (string.valueof (date = null? 0l:date.gettime ())); } public void focusgained (FocusEvent arg0) {System.out.println ("Datestr focusgained.                ............................."); Textdatestr.selectAll ();        }        }); Textdatestr.addmouselistener (New MouseListener () {public void mouseUp (MouseEvent arg0) {} PU                Blic void MouseDown (MouseEvent arg0) {} public void MouseDoubleClick (MouseEvent arg0) {            Textdatestr.selectall ();        }        });                Textdatenum.addfocuslistener (New Focuslistener () {public void Focuslost (FocusEvent arg0) {                Textdatenum.clearselection (); Textdatestr.settext (Dateformatutils.format (Numberutils.tolong (Textdatenum.gettext ()), "Yyyy-MM-dd HH:mm:ss.            SSS ")); } public void focusgained (FocusEvent arg0) {System.out.println ("Datenum focusgained.                .............................");            Textdatenum.selectall ();        }        }); Textdatenum.addmouselistener (New MouseListener () {public void mouseUp (MouseEvent arg0) {} PU Blic void MouseDown (MouseEvent arg0) {} public void MouseDoubleClick (MouseEvent arg0) {T            Extdatenum.selectall ();    }        });        } private void Convert (text textdatestr, text textdatelong) {String datestr = Textdatestr.gettext ();        String datenum = Textdatelong.gettext (); if (Stringutils.isempty (DATESTR)) {if (Stringutils.isempty (Datenum)) {Long T                Imeinmillis = System.currenttimemillis (); Textdatestr.settext (Dateformatutils.format (Timeinmillis, "Yyyy-mm-dd HH:mm:ss.                SSS "));            Textdatelong.settext (string.valueof (Timeinmillis));                } else {Long Timeinmillis = Numberutils.tolong (datenum); Textdatestr.settext (Dateformatutils.format (Timeinmillis, "Yyyy-mm-dd HH:mm:ss.            SSS ")); }} else if (Stringutils.isempty (Datenum)) {Date date = Dateformatutils.toDate (Datestr, "Yyyy-mm-dd HH:mm:ss.            SSS ");        Textdatelong.settext (string.valueof (date = null? 0l:date.gettime ()));         }} private void Generatespliterlabel (Group parentgroup) {Label label = new Label (Parentgroup, 16777224);    Label.setlayoutdata (New Griddata (131072, 16777216, True, False, 1, 1)); } private void Generatetextlabel (Group parentgroup, String labelText) {Label label = new Label (Parentgroup,        16777224);        Label.setlayoutdata (New Griddata (131072, 16777216, True, False, 1, 1));        Label.settext (LabelText);    Label.setfont (Fontutils.getconsolas ()); } Private Text Generatetext (Group parentgroup, String defaulttext, string name) {text text = new text (Parent        Group, 2048);        Griddata griddata = new Griddata (4, 16777216, True, False, 3, 1);        Griddata.widthhint = 280;        griddata.heighthint= 20;        Text.setlayoutdata (Griddata);        Text.setdata ("name", name); Text.settext (DefaultText);        Text.settextlimit (50);        Text.setfont (Fontutils.getconsolas ());    return text;        } protected void configlog4j () {String level = "DEBUG";        Properties Properties = new properties ();        Properties.setproperty ("Log4j.rootlogger", Level + ", application");        Properties.setproperty ("log4j.rootLogger.encoding", "UTF-8");        Properties.setproperty ("Log4j.logger.org.apache", "INFO");        Properties.setproperty ("Log4j.logger.org.springframework", "INFO");        Properties.setproperty ("Log4j.appender.application", "Org.apache.log4j.DailyRollingFileAppender");        Properties.setproperty ("Log4j.appender.application.File", "DateFormatMainUI.log");        Properties.setproperty ("Log4j.appender.application.Append", "true"); Properties.setproperty ("Log4j.appender.application.DatePattern", "'. ')        Yyyy-mm-dd ");        Properties.setproperty ("Log4j.appender.application.layout", "org.apache.log4j.PatternLayout"); Properties.SetProperty ("Log4j.appender.application.layout.ConversionPattern", "%d [%t]%-5p%c{6} (%f:%l)-%m%n");    Propertyconfigurator.configure (properties); }}

 

Import Java.text.parseexception;import java.text.simpledateformat;import java.util.calendar;import java.util.Date; Import Org.apache.commons.lang.time.fastdateformat;import Org.slf4j.logger;import Org.slf4j.loggerfactory;public    Class dateformatutils{protected static final Logger Logger = Loggerfactory.getlogger (Dateformatutils.class);    public static final String Date_time_formatter_default = "Yyyy-mm-dd ' T ' HH:mm:ss ' Z '";    public static final String Date_time_formatter_standard = "Yyyy-mm-dd HH:mm:ss";    public static final String Date_time_formatter_standard_tz = "Yyyy-mm-dd ' T ' HH:mm:ss ' Z '"; public static final String Date_time_formatter_long = "Yyyy-mm-dd HH:mm:ss.    SSS "; public static final String Date_time_formatter_long_tz = "Yyyy-mm-dd ' T ' HH:mm:ss.    SSS ' Z '; public static final String date_time_formatter_net = "Yyyy-mm-dd HH:mm:ss.    SSS ";    public static final Long timemillis_for_one_day = 86400000L; public static String format (long date) {Fastdateformat df = Fastdateformat.getinstance ("Yyyy-mm-dd ' T ' HH:mm:ss ' Z ');    return Df.format (date); The public static string format (long date, string format) {Fastdateformat df = fastdateformat.getinstance (Form        at);    return Df.format (date); The public static String format (date date) {Fastdateformat df = fastdateformat.getinstance ("Yyyy-mm-dd ' T ' hh:mm        : ss ' Z ' ");    return Df.format (date); The public static string format (date date, string format) {Fastdateformat df = fastdateformat.getinstance (Form        at);    return Df.format (date); The public static string format (string datestr, String Srcformat, String dstformat) {Date date = ToDate (datest        R, Srcformat);        Fastdateformat df = fastdateformat.getinstance (Dstformat);    return Df.format (date); public static Date ToDate (string datestr, string pattern) {try {SimpleDateFormat Datefo            Rmat = new SimpleDateFormat (pattern); Return DATEFORmat.parse (DATESTR);    } catch (ParseException e) {} return null;        public static String format___ (date date) {Fastdateformat df = fastdateformat.getinstance ("YYYYMMDDHH");    return Df.format (date);        } public static long Getmonthfirstday (long timeinmillis) {Calendar calendar = calendar.getinstance ();        Calendar.settimeinmillis (Timeinmillis);        Calendar.set (5, Calendar.getactualminimum (5));        Calendar.set (One, Calendar.getactualminimum (11));        Calendar.set (Calendar.getactualminimum (12));        Calendar.set (Calendar.getactualminimum (13));        Calendar.set (+, Calendar.getactualminimum (14));    Return Calendar.gettime (). GetTime ();        } public static long Getmonthlastday (long timeinmillis) {Calendar calendar = calendar.getinstance ();        Calendar.settimeinmillis (Timeinmillis);        Calendar.set (5, Calendar.getactualmaximum (5)); Calendar.set (One, Calendar.getactualmaximum (11));        Calendar.set (Calendar.getactualmaximum (12));        Calendar.set (Calendar.getactualmaximum (13));        Calendar.set (+, Calendar.getactualmaximum (14));    Return Calendar.gettime (). GetTime ();        } public static long Getdatebegintime (long timeinmillis) {Calendar calendar = calendar.getinstance ();        Calendar.settimeinmillis (Timeinmillis);        Calendar.set (One, Calendar.getactualminimum (11));        Calendar.set (Calendar.getactualminimum (12));        Calendar.set (Calendar.getactualminimum (13));        Calendar.set (+, Calendar.getactualminimum (14));    Return Calendar.gettime (). GetTime ();        } public static long Getdateendtime (long timeinmillis) {Calendar calendar = calendar.getinstance ();        Calendar.settimeinmillis (Timeinmillis);        Calendar.set (One, Calendar.getactualmaximum (11));        Calendar.set (Calendar.getactualmaximum (12));        Calendar.set (Calendar.getactualmaximum (13)); Calendar.set(Calendar.getactualmaximum (14));    Return Calendar.gettime (). GetTime ();        public static string Getnextday (string datestr, string format) {Date date = ToDate (datestr, format);        Calendar calendar = Calendar.getinstance ();        Calendar.settime (date);        Calendar.set (5, Calendar.get (5) + 1);    return format (Calendar.gettime (), format);        public static string Getlatestsunday (string datestr, string format) {Date date = ToDate (datestr, format);        Calendar calendar = Calendar.getinstance ();        Calendar.settime (date);    return format (Date.gettime () + (8-calendar.get (7)) * 86400000L, format); public static string Getlatestmonthend (string datestr, string format) {Date date = ToDate (datestr, format)        ;        Calendar calendar = Calendar.getinstance ();        Calendar.settime (date);        Calendar.set (2, Calendar.get (2) + 1);        Calendar.set (5, Calendar.getactualminimum (5)); return Format (caleNdar.gettime (), format);        } public static void Main (string[] args) {System.out.println (Getnextday ("150205", "YYMMDD"));        System.out.println (Getlatestsunday ("150205", "YYMMDD"));        System.out.println (Getlatestmonthend ("150205", "YYMMDD"));        System.out.println (Getnextday ("150208", "YYMMDD"));        System.out.println (Getlatestsunday ("150209", "YYMMDD"));    System.out.println (Getlatestmonthend ("150209", "YYMMDD")); }}

  

Import Org.eclipse.swt.graphics.font;import Org.eclipse.swt.widgets.display;public class fontutils{    static final int font_hight_default = n;    static final int font_hight_banner =;    static font bannerfont = new Font (display.getcurrent (), "Blackbody", 1);    static font Consolas = new Font (display.getcurrent (), "Consolas", 0);    public static Font Getbanner ()    {        return bannerfont;    }    public static Font Getconsolas ()    {        return consolas;    }}

  

 

Java window Program string time to Timestamp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.