⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systemutil.java

📁 ssh整合在一起的例子.适合初学者,希望对大家能有一定的帮助作用
💻 JAVA
字号:
package com.softdevelopstudio.util;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.*;
/**
 *
 * <p>Title:系统设计时的辅助类.</p>
 *
 * <p>Description:一般包含一些全局变量,全局常用api等  </p>
 *
 * <p>Copyright: Copyright (c) 2008</p>
 *
 * <p>Company: </p>
 *
 * @author lzx
 * @version 1.0
 */
public class SystemUtil {
    //每页多少条
    public static int perpage = 20;


    public SystemUtil() {
        super();
    }

    public static boolean isNotNull(String str) {
        if (str != null && !str.equals("")) {
            return true;
        }
        return false;
    }

    public static boolean isNotNull(Object obj) {
        if (obj == null) {
            return false;
        }
        return true;
    }
    /**
     * 将日期只提取年份并转成整型
     * @param date Date
     * @return int
     */
    public static int getYear(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("yyyy");
        String tmpYear = sdf.format(date);
        int year = Integer.parseInt(tmpYear);
        return year;
    }
    /**
     * 将日期转成指定格式的字符串
     * @param date Date
     * @return String
     */
    public static String getFormatDate(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
        String formatDate = sdf.format(date);
        return formatDate;
    }

    public static String getStrDate(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("yyyy-MM-dd");
        String formatDate = sdf.format(date);
        return formatDate;
    }
    /**
     * 返回格式为:yyyy-MM-dd
     * @param date Date
     * @return Date
     */
    public static Date getMyFormatDate(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("yyyy-MM-dd");
        String formatDate = sdf.format(date);
        Date d = null;
        try {
            d = sdf.parse(formatDate);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return d;
    }
    /**
     * 将一个字符转成日期
     * @param tmpDate String
     * @return Date
     */
    public static Date date(String tmpDate){
        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.applyPattern("yyyy-MM-dd");
        Date date = new Date();
        try{
            date = sdf.parse(tmpDate);
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return date;
    }

    public static void main(String[] args) {
        SystemUtil systemutil = new SystemUtil();
        Date now = new Date();
        System.out.println(systemutil.getFormatDate(now));
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -