---
title: "字符串和日期的转换"
author: "nsk696"
date: "2009-04-01T14:14:56Z"
tags: ["C", "C#", "C++", "Java"]
slug: "untitled"
draft: false
lastmod: "2009-04-01T14:14:56Z"
id: 359022
url: "https://nsk696.iteye.com/blog/359022"
---

```java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class TestDate2 {
	public static void main(String[] args) {
		
		
		
		Calendar c = Calendar.getInstance();
		c.clear();
        
        
        SimpleDateFormat sd2 = new SimpleDateFormat("yyyyMMdd-HH:mm:ss.SSS");
		try {
			c.setTime(sd2.parse("20090331-08:11:16.500"));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		
		
		
		String s = sd.format(c.getTime());
		System.out.println(s);
		
		
		
	}
}
```