Java Date to String dateToFMDate(Date date)

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

Description

date To FM Date

License

Open Source License

Declaration

static public String dateToFMDate(Date date) 

Method Source Code

//package com.java2s;
/*/*from   w  w w.j a  v  a 2s  . com*/
 * Copyright (C) 2007-2009  Medsphere Systems Corporation
 * All rights reserved.
 *
 * This source code contains the intellectual property
 * of its copyright holder(s), and is made available
 * under a license. If you do not know the terms of
 * the license, please stop and do not read further.
 *
 * Please read LICENSES for detailed information about
 * the license this source code file is available under.
 * Questions should be directed to legal@medsphere.com
 *
 */

import java.text.DecimalFormat;

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

public class Main {
    private static DecimalFormat fmDatePartFormat = new DecimalFormat(
            "0000000");

    static public String dateToFMDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int year = cal.get(Calendar.YEAR) - 1700;
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        int datePart = year * 10000 + month * 100 + day;
        StringBuffer result = new StringBuffer(
                fmDatePartFormat.format(datePart));
        if (hour + minute + second != 0) {
            result.append(".");
            if (hour < 10) {
                result.append("0");
            }
            result.append(Integer.toString(hour));
            if (minute + second != 0) {
                if (minute < 10) {
                    result.append("0");
                }
                result.append(Integer.toString(minute));
                if (second != 0) {
                    if (second < 10) {
                        result.append("0");
                    }
                    result.append(Integer.toString(second));
                }
            }
        }
        return result.toString();
    }
}

Related

  1. dateToBOMCStrDate(Date date)
  2. dateToCalendar(Date fecha, String formato)
  3. dateToDateString(Date date, Locale locale)
  4. dateToDDMMYYYYStr(Date dateTime)
  5. dateToDefaultDateString(Date date)
  6. dateToFormattedString(Date toFormat)
  7. dateToHHmmStr(Date date)
  8. dateToHMTime(Date date)
  9. dateToHttpDateString(Date d)