java date with Timezone

java date with Timezone

how to set timezone for date in java

refer‮ttual:ot ‬uri.com
/**
 * @author lautturi.com
 * Java example: java date with timezone example
 */

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

public class Lautturi {

	public static void main(String[] args) {

		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
		formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

		// Date date = new Date("Sat Nov 02 12:34:56 GMT 2019");
		Date date = new Date();

		String format = formatter.format(date);
		System.out.println(format);

	}
}

output:

2019-11-25T10:23:24.189Z
Created Time:2017-09-22 18:24:30  Author:lautturi