Example usage for java.util Locale CHINA

List of usage examples for java.util Locale CHINA

Introduction

In this page you can find the example usage for java.util Locale CHINA.

Prototype

Locale CHINA

To view the source code for java.util Locale CHINA.

Click Source Link

Document

Useful constant for country.

Usage

From source file:Main.java

private static String getDayOfWeek(String format, int calendarField) {
    String strDate = null;/*  ww  w  .j av a  2 s . c o  m*/
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        int week = c.get(Calendar.DAY_OF_WEEK);
        if (week == calendarField) {
            strDate = mSimpleDateFormat.format(c.getTime());
        } else {
            int offectDay = calendarField - week;
            if (calendarField == Calendar.SUNDAY) {
                offectDay = 7 - Math.abs(offectDay);
            }
            c.add(Calendar.DATE, offectDay);
            strDate = mSimpleDateFormat.format(c.getTime());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strDate;
}

From source file:Main.java

public static String timeFormat(long timeMillis, String pattern) {
    SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.CHINA);
    return format.format(new Date(timeMillis));
}

From source file:Main.java

public static Uri getOutputMediaFileUri() {
    File mediaStorageDir = new File(
            Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Date");
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("Date", "failed to create directory");
            return null;
        }// w  ww. j  ava 2  s . c o  m
    }

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date());
    File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");

    return Uri.fromFile(mediaFile);
}

From source file:Main.java

public static long getDateMills(int year, int month, int day) {
    //Date d = new Date(year, month, day);
    // 1960 4 22//www.ja v a2 s.c  o m
    Calendar calendar = Calendar.getInstance(Locale.CHINA);
    calendar.set(year, month, day);
    TimeZone tz = TimeZone.getDefault();
    calendar.setTimeZone(tz);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static String generateTime(long time, boolean isLong) {
    Date date = new Date(time);
    sFORMAT.applyPattern(isLong ? FORMAT_ALL_DATE : FORMAT_TIME);
    String LgTime = null;//  ww  w . jav  a2s  . c  o  m
    try {
        LgTime = sFORMAT.format(date);
    } catch (Exception e) {
        try {
            SimpleDateFormat format = new SimpleDateFormat(isLong ? FORMAT_ALL_DATE : FORMAT_TIME,
                    Locale.CHINA);
            LgTime = format.format(new Date());
            e.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
            LgTime = "";
        }
    }
    return LgTime;
}

From source file:Main.java

public static Calendar getCalendar() {
    return Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"), Locale.CHINA);
}

From source file:Main.java

public static String saveFile(Context c, String filePath, String fileName, byte[] bytes) {
    String fileFullName = "";
    FileOutputStream fos = null;// w w w.  j a va 2  s.c o  m
    String dateFolder = new SimpleDateFormat("yyyyMMdd", Locale.CHINA).format(new Date());
    try {
        String suffix = "";
        if (filePath == null || filePath.trim().length() == 0) {
            filePath = Environment.getExternalStorageDirectory() + "/tuiji/" + dateFolder + "/";
        }
        File file = new File(filePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        File fullFile = new File(filePath, fileName + suffix);
        fileFullName = fullFile.getPath();
        fos = new FileOutputStream(new File(filePath, fileName + suffix));
        fos.write(bytes);
    } catch (Exception e) {
        fileFullName = "";
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                fileFullName = "";
            }
        }
    }
    return fileFullName;
}

From source file:Main.java

public static String convertUtc2LocalPro(String utcTime) {
    if (TextUtils.isEmpty(utcTime)) {
        return "";
    }/*w w w  . j  av  a  2  s  .c  o m*/
    // 2014-10-24T02:58:05.932Z
    SimpleDateFormat utcFormatter, localFormatter;
    utcFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
    Date date;
    Calendar cal = Calendar.getInstance();
    try {
        date = utcFormatter.parse(utcTime);
        cal.setTime(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    cal.add(Calendar.HOUR_OF_DAY, +8);
    date = cal.getTime();
    localFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
    return localFormatter.format(date);
}

From source file:Main.java

private static File createMediaFile(Context context, String parentPath) {
    String state = Environment.getExternalStorageState();
    File rootDir = state.equals(Environment.MEDIA_MOUNTED) ? Environment.getExternalStorageDirectory()
            : context.getCacheDir();/*  w ww .j a v a2  s . c o m*/

    File folderDir = new File(rootDir.getAbsolutePath() + parentPath);
    if (!folderDir.exists() && folderDir.mkdirs()) {

    }

    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA).format(new Date());
    String fileName = APP_NAME + "_" + timeStamp + "";
    File tmpFile = new File(folderDir, fileName + POSTFIX);
    return tmpFile;
}

From source file:Main.java

public static String getStringByOffset(Date date, String format, int calendarField, int offset) {
    String strDate = null;/*  ww  w. j ava  2 s.co  m*/
    try {
        Calendar c = new GregorianCalendar();
        SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat(format, Locale.CHINA);
        c.setTime(date);
        c.add(calendarField, offset);
        strDate = mSimpleDateFormat.format(c.getTime());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return strDate;
}