Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    /**
     *  Gets the node value as date.
     *
     *@param  node                          Description of the Parameter
     *@return                               The nodeValueAsDate value
     *@exception  DOMException              Description of the Exception
     *@exception  ParseException  Description of the Exception
     */
    public final static Date getNodeValueAsDate(Node node) throws DOMException, ParseException {
        if (node == null)
            return null;

        NamedNodeMap attrs = node.getAttributes();
        Node attr = attrs.getNamedItem("DateTimeFormat");

        // Date format
        String format = attr.getNodeValue().trim();
        node = node.getFirstChild();
        if (node != null) {
            String date = node.getNodeValue().trim();
            DateFormat df = new SimpleDateFormat(format);
            return df.parse(date);
        }
        return null;
    }
}