---
title: "Java 代码"
author: "shelllgd"
date: "2011-01-30T11:39:32Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2011-01-30T11:39:32Z"
id: 899681
url: "https://shelllgd.iteye.com/blog/899681"
---

```
/**
     * 去除字符串中的空格，回车，换行，制表符
     * @param before 字符串的值
     * @return 处理后的字符串
     */
    public static String replaceBlank(String before){
        Pattern p = Pattern.compile("\\s*|\t|\r|\n");
        Matcher m = p.matcher(before);
        String after = m.replaceAll("");
        return after;
    }
```

 

```
 //获得本周一的日期   
    public String getMondayOFWeek(){   
        
         int mondayPlus = this.getMondayPlus();   
         GregorianCalendar currentDate = new GregorianCalendar();   
         currentDate.add(GregorianCalendar.DATE, mondayPlus);   
         Date monday = currentDate.getTime();   
            
         DateFormat df = DateFormat.getDateInstance();   
         String preMonday = df.format(monday);   
         return preMonday;   
    } 
    
    // 获得当前日期与本周日相差的天数   
    private int getMondayPlus() {   
        Calendar cd = Calendar.getInstance();   
        // 获得今天是一周的第几天，星期日是第一天，星期二是第二天......   
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK)-1;         //因为按中国礼拜一作为第一天所以这里减1   
        if (dayOfWeek == 1) {   
            return 0;   
        } else {   
            return 1 - dayOfWeek;   
        }   
    }   
```