美文网首页
随机生成订单号

随机生成订单号

作者: 楠Y | 来源:发表于2017-05-13 13:52 被阅读107次

#pragma mark - 订单号(随机生成)

- (NSString *)orderId

{

NSDate * today = [NSDate date];

//转换时间格式

NSDateFormatter * df = [[NSDateFormatter alloc]init];//格式化

[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString * s1 = [df stringFromDate:today];

NSDate * date = [df dateFromString:s1];

//转换时间格式

NSDateFormatter * df2 = [[NSDateFormatter alloc]init];//格式化

[df2 setDateFormat:@"yyyyMMddHHmmssfffffff"];

[df2 setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"]];

NSString *string = [[NSString alloc]init];

for (int i = 0; i < 14; i++) {

int number = arc4random() % 10;

NSString *tempString = [NSString stringWithFormat:@"%d", number];

string = [string stringByAppendingString:tempString];

}

//    NSLog(@"%@",[[df2 stringFromDate:date] stringByAppendingString:string]);

NSString * ordid = [[df2 stringFromDate:date] stringByAppendingString:string];

return ordid;

}

相关文章

网友评论

      本文标题:随机生成订单号

      本文链接:https://www.haomeiwen.com/subject/wluxxxtx.html