Here you can find the source of parseTimestamp(String time)
Parameter | Description |
---|---|
time | should be in the format of xs:dateTime. e.g. <code> 2016-04-05T12:00:00 </code> |
private static boolean parseTimestamp(String time)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Liviu Ionescu.//from ww w . ja v a 2 s .com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Liviu Ionescu - initial implementation. * ARM Ltd and ARM Germany GmbH - application-specific implementation *******************************************************************************/ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static long timestamp = 0; /** * Parse the time * @param time should be in the format of xs:dateTime. * e.g. <code> 2016-04-05T12:00:00 </code> * @return true if the time stamp of the index file has changed */ private static boolean parseTimestamp(String time) { StringBuilder dateFormat = new StringBuilder("yyyy-MM-dd'T'HH:mm:ss"); //$NON-NLS-1$ // if the date contains time zone info, add a 'Z' in the end of the date format int fromIndex = time.lastIndexOf(':'); if (time.indexOf('+', fromIndex) > 0 || time.indexOf('-', fromIndex) > 0) { dateFormat.append('Z'); } try { Date date = new SimpleDateFormat(dateFormat.toString()).parse(time); long ms = date.getTime(); if (ms != timestamp) { timestamp = ms; return true; } } catch (ParseException e) { } return false; } }