Example usage for java.util Date getTime

List of usage examples for java.util Date getTime

Introduction

In this page you can find the example usage for java.util Date getTime.

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:com.greenline.guahao.biz.manager.partners.xm.converter.XmConverter.java

/**
 * ??/*from  w w  w  .  j  a  v a2  s.  com*/
 * 
 * @param date java.util.Date
 * @return
 */
private static long parseTimeToSecond(Date date) {
    long time = 0;
    if (null != date) {
        time = date.getTime() / 1000;
    }
    return time;
}

From source file:ca.travelagency.utils.DateUtils.java

public static String formatDate(Date date) {
    if (date == null) {
        return StringUtils.EMPTY;
    }//from w  w  w .  ja va  2 s .  c o m
    return DateTimeFormat.forStyle(DATE_STYLE).print(date.getTime());
}

From source file:Main.java

public static String readableDate(String dateString) {
    DateFormat input = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ");
    DateFormat output = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    Date date = new Date();
    try {//from w w w.  j  av  a2  s.  co m
        date = input.parse(dateString);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return output.format(date.getTime());
}

From source file:Main.java

/**
 * Converts a java.util.Date into an instance of XMLGregorianCalendar
 *
 * @param date Instance of java.util.Date or a null reference
 * @return XMLGregorianCalendar instance whose value is based upon the
 * value in the date parameter. If the date parameter is null then
 * this method will simply return null.//from  w  w w . j  a va  2 s.co  m
 */
public static XMLGregorianCalendar dateAsCalendar(Date date) {
    if (date == null) {
        return null;
    } else {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(date.getTime());
        return df.newXMLGregorianCalendar(gc);
    }
}

From source file:ca.travelagency.utils.DateUtils.java

public static String formatDateCustom(Date date) {
    if (date == null) {
        return StringUtils.EMPTY;
    }/*from   www . j ava  2 s.c om*/
    return DateTimeFormat.forPattern(DATE_CUSTOM).print(date.getTime());
}

From source file:eu.digitisation.idiomaident.utils.ExtractTestSamples.java

private static String nextSample(File inFolder) {
    File[] langFolders = inFolder.listFiles();

    Date now = new Date();
    Random rand = new Random(now.getTime());

    //get a ramdom language       
    int numLangs = langFolders.length;
    int chosenLang = rand.nextInt(numLangs);

    String lang = langFolders[chosenLang].getName();

    //get a ramdom file from the folder        
    File[] langFiles = langFolders[chosenLang].listFiles();
    int numFiles = langFiles.length;
    int chosenFile = rand.nextInt(numFiles);

    File langFile = langFiles[chosenFile];

    //open and read the file
    try {//from ww  w  .  j  ava  2 s  .c  o m
        String text = FileUtils.readFileToString(langFile, Charset.forName("UTF-8"));

        text = StringNormalize.stringNormalize(text);

        text = text.replaceAll("[\\n.,:;]", " ");
        text = text.trim();

        if (text.replaceAll("[\\p{Space}]+", "").length() < 20) {
            return null;
        }

        //split the text in words
        String[] words = text.split("[\\p{Space}]+");

        boolean correct = false;
        StringBuilder sampleBuild = null;

        while (!correct) {
            //chosen the initial position to read the words
            int actualWord = rand.nextInt(words.length);
            correct = true;

            sampleBuild = new StringBuilder();
            while (sampleBuild.length() < 20) {
                if (actualWord < words.length) {
                    sampleBuild.append(words[actualWord]);
                    sampleBuild.append(" ");
                } else {
                    correct = false;
                    break;
                }

                actualWord++;
            }
        }

        //complete the sample
        sampleBuild.deleteCharAt(sampleBuild.length() - 1);
        sampleBuild.append(";").append(lang).append("\n");

        return sampleBuild.toString();

    } catch (IOException ex) {
        System.out.println(ex.toString());
    }

    return null;
}

From source file:Main.java

public static long getDifferenceinMinutes(Date date1, Date date2) {
    System.out.println(date1.toString());

    System.out.println(date2.toString());

    if (date1 == null || date2 == null)
        return 0;

    long diff = date2.getTime() - date1.getTime();

    long diffMinutes = TimeUnit.MINUTES.convert(diff, TimeUnit.MILLISECONDS);

    return diffMinutes;
}

From source file:ca.travelagency.utils.DateUtils.java

public static String formatDateTime(Date date) {
    if (date == null) {
        return StringUtils.EMPTY;
    }//from   w ww .  j a va2  s  . c  o m
    return DateTimeFormat.forStyle(DATE_TIME_STYLE).print(date.getTime());
}

From source file:ca.travelagency.utils.DateUtils.java

public static String formatDateShort(Date date) {
    if (date == null) {
        return StringUtils.EMPTY;
    }//from ww w .  j  a  v  a  2s  .  com
    return DateTimeFormat.forStyle(DATE_STYLE_SHORT).print(date.getTime());
}

From source file:io.apicurio.studio.fe.servlet.servlets.DownloadServlet.java

private static long expiredSinceYesterday(Date now) {
    return now.getTime() - 86400000L;
}