Java tutorial
//package com.java2s; /* * Copyright (c) Fiorano Software Pte. Ltd. and affiliates. All rights reserved. http://www.fiorano.com * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ import org.w3c.dom.*; public class Main { /** * Gets the node value as time. * *@param node Description of the Parameter *@return The nodeValueAsTime value *@exception DOMException Description of the Exception */ public final static long getNodeValueAsTime(Node node) throws DOMException { if (node == null) return -1; NamedNodeMap attrs = node.getAttributes(); Node attr = attrs.getNamedItem("Unit"); int factor = 1; String unit = attr.getNodeValue(); if (unit.equals("sec")) { factor = 1000; } else if (unit.equals("min")) { factor = 60000; } else if (unit.equals("hr")) { factor = 3600000; } else if (unit.equals("day")) { factor = 86400000; } node = node.getFirstChild(); if (node != null) { String time = node.getNodeValue().trim(); return Integer.parseInt(time) * factor; } return -1; } }