Example usage for java.sql Date Date

List of usage examples for java.sql Date Date

Introduction

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

Prototype

public Date(long date) 

Source Link

Document

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Usage

From source file:Main.java

/**
 * Helper method to get the date and time from timestamp. Converts the Timestamp in Milliseconds to Date and Time and then
 * formats the Date object with {@link Format} and returns the String of Date and Time.
 *
 * @return//from   w  w  w.  j ava2 s.c o m
 */
public static String getDateAndTime(long timestamp) {
    Date date = new Date(timestamp);
    Format dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss", Locale.US);
    return dateFormat.format(date);
}

From source file:Main.java

/**
 * Helper method to get the date and time from timestamp. Converts the Timestamp in Milliseconds to Date and Time and then
 * formats the Date object with {@link Format} and returns the String of Date and Time.
 *
 * @return/*from w  w  w.  jav  a  2s .  c o  m*/
 */
public static String getFullDateAndTime(long timestamp) {
    Date date = new Date(timestamp);
    Format dateFormat = new SimpleDateFormat("EEEE, dd MMMM yyyy, hh:mm a", Locale.US);
    return dateFormat.format(date);
}

From source file:Main.java

/**
 * Helper method to get the date and time from timestamp. Converts the Timestamp in Milliseconds to Date and Time and then
 * formats the Date object with {@link Format} and returns the String of Date and Time separately respectively
 *
 * @return String[] containing Date and Time
 *///from  w  ww  .  j a  v  a 2s. c  om
public static String[] getDateAndTimeSeparate(long timestamp) {
    Date date = new Date(timestamp);
    Format dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.US);
    String dateTime = dateFormat.format(date);
    return dateTime.split(" ");
}

From source file:Main.java

public static String formateDateToString(Object longDate) {
    String time = null;/*from  www .  j  a v a2 s  .co  m*/
    if (longDate instanceof String) {
        time = (String) longDate;
        if (!TextUtils.isEmpty(time) && time.length() >= 16) {
            time = ((String) longDate).substring(0, 16);
        }
    } else if (longDate instanceof Long) {
        SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date date = new Date((Long) longDate);
        time = formatDate.format(date);
    }
    return time.trim();
}

From source file:Main.java

public static String formatTimeAgo(long time) {
    long diff = System.currentTimeMillis() - time;

    long day = diff / DAY;
    if (day > 0) {
        if (day > 5) {
            Date date = new Date(time);
            if (date.getYear() != Calendar.getInstance().getTime().getYear()) {
                return FULL_FORMAT.format(date);
            } else {
                return FORMAT.format(date);
            }//from  w w w  .  j a  v  a  2  s  .co  m
        } else {
            return day + (day == 1 ? " day ago" : " days ago");
        }
    }

    long hour = diff / HOUR;
    if (hour > 0) {
        return hour + (hour == 1 ? " hour ago" : " hours ago");
    }

    long minute = diff / MINUTE;
    if (minute > 0) {
        return minute + (minute == 1 ? " minute ago" : " minutes ago");
    }

    return "Just now";
}

From source file:Main.java

public static List<String> getAllNumbers(Activity callingActivity) {
    List<String> allNumbers = new ArrayList<String>();
    Cursor managedCursor = callingActivity.managedQuery(CallLog.Calls.CONTENT_URI, null, null, null, null);
    int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
    int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
    int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
    int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
    StringBuilder sb = new StringBuilder();
    sb.append("Call Details :");
    while (managedCursor.moveToNext()) {
        String phNumber = managedCursor.getString(number);
        String callType = managedCursor.getString(type);
        String callDate = managedCursor.getString(date);
        Date callDayTime = new Date(Long.valueOf(callDate));
        String callDuration = managedCursor.getString(duration);
        String dir = null;//from ww  w  .ja v a2 s  . c  o  m
        if (!allNumbers.contains(phNumber)) {
            allNumbers.add(phNumber);
        }

        int dircode = Integer.parseInt(callType);
        switch (dircode) {
        case CallLog.Calls.OUTGOING_TYPE:
            dir = "OUTGOING";
            break;

        case CallLog.Calls.INCOMING_TYPE:
            dir = "INCOMING";
            break;

        case CallLog.Calls.MISSED_TYPE:
            dir = "MISSED";
            break;
        }
        sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- "
                + callDayTime + " \nCall duration in sec :--- " + callDuration);
        sb.append("\n----------------------------------");
        // Log.i("getAllNumbers", sb.toString());
    }
    managedCursor.close();

    return allNumbers;
}

From source file:com.dianping.lion.dao.ibatis.TeamIbatisDaoTest.java

@Test
public void testInsert() {
    int oriSize = teamDao.findAll().size();
    Team team = new Team();
    team.setName("teamx");
    team.setCreateTime(new Date(System.currentTimeMillis()));
    team.setModifyTime(new Date(System.currentTimeMillis()));
    id = teamDao.create(team);//  w  ww. ja  v  a2 s .c  om
    int nowSize = teamDao.findAll().size();
    assertTrue(nowSize > oriSize);
}

From source file:com.wavemaker.commons.json.deserializer.WMSqlDateDeSerializer.java

public static Date getDate(String value) {
    if (StringUtils.isBlank(value)) {
        return null;
    }/* w w  w.  j  a  v  a  2s.  c o m*/
    try {
        java.util.Date parsedDate = new SimpleDateFormat(DEFAULT_DATE_FORMAT).parse(value);
        return new Date(parsedDate.getTime());
    } catch (ParseException e) {
        throw new WMRuntimeException("Failed to parse the string " + value + "as java.sql.Date", e);
    }
}

From source file:org.apache.hadoop.hive.serde2.io.DateWritable.java

public static Date timeToDate(long l) {
    return new Date(l * 1000);
}

From source file:testRepository.testPatienttest.java

public void getPatients() {
    Patient patient = new Patient();
    patient.setPatientno(19);// www. j  a v a  2  s.  co  m
    patient.setName("Cassim");
    patient.setDob(new Date(20142309));
    patient.setAddress("33458 makhaza Cape Town 1184");
    patient.setPhoneno("078 202 0491");
    patientDao.saveOrUpdate(patient);
    Assert.assertNotNull(patient);
}