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:Main.java

private static void smoothToOrigin(final View view) {
    Date firstDate = new Date();
    final long firstTime = firstDate.getTime();
    executeAsyncTask(new AsyncTask<Void, Integer, Void>() {
        int n = 1, t = 4000;
        boolean increaseN;

        @Override//from w ww .  j  av  a 2s. c  o m
        protected Void doInBackground(Void... params) {
            while (!isCancelled()) {
                Date currentDate = new Date();
                long diffTime = currentDate.getTime() - firstTime;

                double y = getCosY(diffTime);
                int alpha = (int) (y * 255);
                int resultColor = setAlphaComponent(mColor, alpha);
                if (alpha < 0.038 * 255) {
                    publishProgress(0);
                    this.cancel(true);
                    return null;
                }
                publishProgress(resultColor, alpha);
                try {
                    Thread.sleep(38);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            view.setBackgroundColor(values[0]);
        }
    });
}

From source file:Main.java

public static String changeStringToDate3(String str) {

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date date6 = null;
    try {/*  w w  w.j  a  v a2s  .c o m*/
        date6 = sdf.parse(str);
        java.sql.Date date7 = new java.sql.Date(date6.getTime());
        Timestamp stamp9 = new Timestamp(date7.getTime());
        return stamp9.toString();
    } catch (ParseException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:com.ibm.mil.readyapps.telco.analytics.OperationalAnalyticsReporter.java

/**
 * planChangeAccepted() sends an Operational Analytics log anytime a user accepts a plan change.
 *
 * @param planChangeType the type of plan change that a user has accepted (ie baseplan
 *                       increase, baseplan decrease, addon, etc)
 * @param amount the cost amount of the plan change.
 *///from   ww w.ja  v  a 2 s  .  co  m
public static void planChangeAccepted(@AnalyticsCnsts.PlanChange String planChangeType, double amount) {
    // Create a custom activity with a log message
    Date date = new Date();
    Timestamp curTime = new Timestamp(date.getTime());

    String json = gson.toJson(new AnalyticsPlanChange(planChangeType, amount, curTime),
            AnalyticsPlanChange.class);
    JSONObject jsonObject = null;
    try {
        jsonObject = new JSONObject(json);
        jsonObject.put("_activity", "planChanged");

        Log.i("TEST", "JSON AFTER ACTIVITY " + jsonObject.toString());

        WLAnalytics.log("Plan change accepted by a user", jsonObject); //async
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.ocpsoft.socialpm.util.Dates.java

public static long calculateNumberOfDaysBetween(final Date one, final Date two) {
    long milisOne = one.getTime();
    long milisTwo = two.getTime();
    long diff = milisTwo - milisOne;

    // Calculate difference in days
    long diffDays = diff / (24 * 60 * 60 * 1000);

    return diffDays;
}

From source file:Main.java

/**
 * Get Calendar from Date//  w w  w .  j av  a  2s. c  o  m
 * @param date Date
 * @return Calendar generated
 */
public static Calendar generateCalendar(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date.getTime());
    return c;
}

From source file:Main.java

/**
 * Get the long representation of the beginning of the current date
 * @return current date in system time/*w  w  w .  j a v a 2  s .c  o  m*/
 */
public static long getCurrentDateStartLong() {
    final Date currentDate = new Date(System.currentTimeMillis());
    final Date currentDateBeginning = new Date(currentDate.getYear(), currentDate.getMonth(),
            currentDate.getDate());

    return currentDateBeginning.getTime();
}

From source file:net.kamhon.ieagle.jdbc.oracle.OracleUtil.java

/**
 * /*from  ww  w.  j a  va  2  s.c o m*/
 * @param rowSet
 * @param fieldName
 * @return
 */
public static Date getDate(SqlRowSet rowSet, String fieldName) {
    Date date = null;

    Object object = rowSet.getObject(fieldName);
    if (object instanceof TIMESTAMP) {
        TIMESTAMP timestamp = (TIMESTAMP) object;
        try {
            date = new Date(timestamp.dateValue().getTime());
        } catch (Exception ex) {
        }
    } else if (object instanceof Timestamp) {
        Timestamp timestamp = (Timestamp) object;
        date = new Date(timestamp.getTime());
    } else if (object instanceof java.sql.Date) {
        java.sql.Date sqlDate = (java.sql.Date) object;
        date = new Date(sqlDate.getTime());
    }

    return date;
}

From source file:com.ibm.mil.readyapps.telco.analytics.OperationalAnalyticsReporter.java

/**
 * pageTransition() sends an Operational Analytics log anytime a user changes from one screen
 * to another.// w w  w  . j  a  v a 2 s  .co m
 *
 * @param src The source page that the user is navigating from.
 * @param dst The destination page that the user navigates to, it refers to there current
 *            screen.
 * @param dwellTime The dwellTime in milliseconds that the user spent on the source page
 *                  before transitioning to the destination page.
 */
public static void pageTransition(@AnalyticsCnsts.Page String src, @AnalyticsCnsts.Page String dst,
        long dwellTime) {
    Date date = new Date();
    Timestamp curTime = new Timestamp(date.getTime());

    String json = gson.toJson(new AnalyticsPageTransition(src, dst, curTime), AnalyticsPageTransition.class);
    JSONObject jsonObject = null;
    try {
        jsonObject = new JSONObject(json);
        jsonObject.put("_activity", "pageTransition");
        String dwellField = src + "_dwellTime";
        double dwellTimeSeconds = (double) dwellTime / 1000;
        jsonObject.put(dwellField, dwellTimeSeconds);

        Log.i("TEST", "PAGE_TRANSITION : " + jsonObject.toString());

        WLAnalytics.log("Page transition recorded.", jsonObject);

        WLAnalytics.send();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.oncecorp.visa3d.bridge.utility.JdbcUtils.java

/**
 * This method converts the java date object into the <tt>long</tt> type
 * value that includes the day and time.
 * @param date The java date object.//from www  .java2 s.  com
 * @return The <tt>long</tt> type value.
 */
public static long dateValue(Date date) {
    return date.getTime();
}

From source file:Main.java

public static long parseDateTime(String dateTime) {
    if (TextUtils.isEmpty(dateTime)) {
        return 0;
    }// w  ww . ja v a 2s  .  c o m

    long time = 0;
    try {
        Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateTime);
        if (null != date) {
            time = date.getTime();
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    return time;
}