zoukankan      html  css  js  c++  java
  • Web 开发工具类(4): IDUtils

    package com.easybuy.utils;
    
    import java.util.Random;
    
    /**
     * 
     * <p>Title: IDUtils</p>
     * <p>Description: </p>
     * <p>Company: www.evanshare.com</p> 
     * @author	Evan
     * @date	2016年4月4日下午5:18:29
     * @version 1.0
     */
    public class IDUtils {
    
    	/**
    	 * 图片名生成
    	 */
    	public static String genImageName() {
    		//取当前时间的长整形值包含毫秒
    		long millis = System.currentTimeMillis();
    		//long millis = System.nanoTime();
    		//加上三位随机数
    		Random random = new Random();
    		int end3 = random.nextInt(999);
    		//如果不足三位前面补0
    		String str = millis + String.format("%03d", end3);
    		
    		return str;
    	}
    	
    	/**
    	 * 商品id生成
    	 */
    	public static long genItemId() {
    		//取当前时间的长整形值包含毫秒
    		long millis = System.currentTimeMillis();
    		//long millis = System.nanoTime();
    		//加上两位随机数
    		Random random = new Random();
    		int end2 = random.nextInt(99);
    		//如果不足两位前面补0
    		String str = millis + String.format("%02d", end2);
    		long id = new Long(str);
    		return id;
    	}
    	
    	public static void main(String[] args) {
    		for(int i=0;i< 100;i++)
    		System.out.println(genItemId());
    	}
    }
    

  • 相关阅读:
    剑指 Offer 46. 把数字翻译成字符串
    leedcode:27. 移除元素
    1052. 爱生气的书店老板(滑动窗口)
    剑指 Offer 56
    剑指 Offer 11. 旋转数组的最小数字(二分)
    1919年巴黎和会顾维钧英语演讲稿
    状语从句
    定语从句
    名词性从句
    并列句
  • 原文地址:https://www.cnblogs.com/evan-liang/p/12233968.html
Copyright © 2011-2022 走看看