字符串组装-将时间转换成String并补足位数_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 字符串组装-将时间转换成String并补足位数

字符串组装-将时间转换成String并补足位数

 2012/4/23 12:40:11  羽鹤彬  程序员俱乐部  我要评论(0)
  • 摘要:packagetest;importjava.text.NumberFormat;importjava.text.SimpleDateFormat;importjava.util.Date;/***生成编码*@authorAdministrator**/publicclassTest{publicstaticvoidmain(String[]args){StringBuffersb=newStringBuffer();char[]projectTypes={'B','S'}
  • 标签:字符串
package test;

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

/**
* 生成编码
* @author Administrator
*
*/
public class Test {
    public static void main(String[] args){
        StringBuffer sb = new StringBuffer();
        char[] projectTypes = {'B','S'};
        char[] listingTypes = {'R','D','G'};
        //将时间转换成String
        Date date = new Date();
        System.out.println("++++++++++++++++"+date+"++++++++++++++++");
        SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd");
        String dateString = formatter.format(date);
        System.out.println("转换后String类型的时间"+dateString);
        sb.append(projectTypes[0]).append(listingTypes[0]).append(dateString);
       
        System.out.println("++++++++++++++++"+sb+"++++++++++++++++++");
       
        //code后面6位,补不足补零
        Long n = 1005l;  
        NumberFormat numFormatter = NumberFormat.getNumberInstance();  
        numFormatter.setMinimumIntegerDigits(6);  
        numFormatter.setGroupingUsed(false);  
        String s = numFormatter.format(n); 
       
        System.out.println("++++++++++++++++"+s+"++++++++++++++++");
        sb.append(s);
        String code = sb.toString();
       
        System.out.println("-----------------"+code+"----------------");


    }
}
发表评论
用户名: 匿名