Java String to Time getSystemTime(String pattern)

Here you can find the source of getSystemTime(String pattern)

Description

Gets the system time.

License

Open Source License

Return

the system time

Declaration

public static String getSystemTime(String pattern) 

Method Source Code

//package com.java2s;
/*/*www.j ava 2  s .com*/
 * DateUtil.java
 * Copyright (c) 2014, CODEROAD, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of CODEROAD
 * ("Confidential Information"). You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you entered into with
 * CODEROAD.
 */

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.joda.time.DateTime;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class Main {
    /**
     * Gets the system time.
     * 
     * @return the system time
     */
    public static String getSystemTime(String pattern) {

        long secs = System.currentTimeMillis();
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        Date date = new Date(secs);
        return sdf.format(date);
    }

    /**
     * Format.
     * 
     * @param calendar the calendar
     * @param pattern the pattern
     * @return the string
     */
    public static String format(Calendar calendar, String pattern) {

        DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
        return fmt.print(new DateTime(calendar));
    }

    /**
     * Format.
     * 
     * @param date the date
     * @param pattern the pattern
     * @return the string
     */
    public static String format(Date date, String pattern) {

        DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
        String strDate = fmt.print(new DateTime(date));
        return strDate;
    }
}

Related

  1. getFormerDate(String dateTime)
  2. getIdByTime(String name)
  3. getMReportTime(String time)
  4. getSignTime(final String stStr)
  5. getStringWithTime(String str)
  6. getTime(String date)
  7. getTime(String date, String pattern)
  8. getTime(String dateTimeString)
  9. getTime(String file)