< prev index next >

src/java.base/share/classes/java/time/OffsetTime.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 1230,1239 **** --- 1230,1253 ---- long nod = time.toNanoOfDay(); long offsetNanos = offset.getTotalSeconds() * NANOS_PER_SECOND; return nod - offsetNanos; } + /** + * Converts this {@code OffsetTime} to the number of seconds since the epoch + * of 1970-01-01T00:00:00Z. + * <p> + * This returns the number of seconds from the epoch for this {@link OffsetTime}. + * + * @return the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative + */ + public int toEpochSecond() { + int secs = time.toSecondOfDay(); + secs -= offset.getTotalSeconds(); + return secs; + } + //----------------------------------------------------------------------- /** * Compares this {@code OffsetTime} to another time. * <p> * The comparison is based first on the UTC equivalent instant, then on the local time.
< prev index next >