Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 This file is part of dgAlert Classic.
    
 dgAlert Classic is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 dgAlert Classic is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with dgAlert Classic.  If not, see <http://www.gnu.org/licenses/>.
 */

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

import android.content.Context;

import android.provider.Settings;

public class Main {
    private static final String TIME_FORMAT_12_HOUR = "h:mm a";
    private static final String TIME_FORMAT_24_HOUR = "H:mm";

    public static String formatTimestamp(Context context, long timestamp) {
        String HOURS_24 = "24";
        String hours;
        hours = Settings.System.getString(context.getContentResolver(), Settings.System.TIME_12_24);

        SimpleDateFormat mSDF = new SimpleDateFormat();
        if (HOURS_24.equals(hours)) {
            mSDF.applyLocalizedPattern(TIME_FORMAT_24_HOUR);
        } else {
            mSDF.applyLocalizedPattern(TIME_FORMAT_12_HOUR);
        }
        return mSDF.format(new Date(timestamp));
    }
}