get Time String - Android java.util

Android examples for java.util:Time

Description

get Time String

Demo Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

import android.annotation.SuppressLint;

public class Main {
    public static final String COMMON_FORMAT = "yyyy.MM.dd HH:mm:ss";

    @SuppressLint("NewApi")
    public static String getTimeString(String strFormat) {
        if (strFormat.isEmpty()) {
            strFormat = COMMON_FORMAT;/*from w w w  . jav  a2s  .c o m*/
        }

        SimpleDateFormat sd = new SimpleDateFormat(strFormat);

        String str = sd.format(new Date());

        return str;
    }
}

Related Tutorials