Java Date Format convertDateToRpcFormat(Date date)

Here you can find the source of convertDateToRpcFormat(Date date)

Description

convert Date To Rpc Format

License

Apache License

Parameter

Parameter Description
date a parameter

Return

- a String representation of the date in the format needed to make an RPC call or a zero-length string if date is null.

Declaration

public static String convertDateToRpcFormat(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**/*from w  w w . j  a  v a2  s. c o m*/
     * 
     * @param date
     * @return - a String representation of the date in the format needed to make
     * an RPC call or a zero-length string if date is null.
     */
    public static String convertDateToRpcFormat(Date date) {
        if (date == null)
            return "";

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        // int hour = calendar.get(Calendar.HOUR_OF_DAY);
        // int minute = calendar.get(Calendar.MINUTE);
        //int second = calendar.get(Calendar.SECOND);

        String mDateFormat = "";
        /*
        int yearDifference = ((year - 1700) / 100);
        mDateFormat = yearDifference + "";
        year = (year % 100);
         */

        DecimalFormat twoDigitFormat = new DecimalFormat("00");

        mDateFormat = twoDigitFormat.format(month) + "/"
                + twoDigitFormat.format(day) + "/" + year;

        /*
        mDateFormat += twoDigitFormat.format(year) + twoDigitFormat.format(month) + twoDigitFormat.format(day) + twoDigitFormat.format(hour) + 
        twoDigitFormat.format(minute) + twoDigitFormat.format(second);
         */
        return mDateFormat;
    }
}

Related

  1. convertDateToFileName(final Date datum)
  2. convertDateToGMTDateString(Date date)
  3. convertDateToHour(Date d)
  4. convertDateToISO8601(Date date)
  5. convertDateToMMDDYYYY(Date date)
  6. convertDateToString(Date aDate)
  7. convertDateToString(Date aDate)
  8. convertDateToString(Date date)
  9. convertDateToString(Date date)