Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:32:51+00:00 2026-06-10T20:32:51+00:00

I have written two functions – today() and todayUTC() – as: public static Date

  • 0

I have written two functions – today() and todayUTC() – as:

public static Date today() {
  Calendar cal = Calendar.getInstance();
  return cal.getTime();
}

public static Date todayUTC() {
  Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
  return cal.getTime();
}

But when I print the results of these functions using:

public void todayTest() {
  Date date1 = OOTBFunctions.today();
  System.out.println("today: "+date1);

  Date dateUTC1 = OOTBFunctions.todayUTC();
  System.out.println("todayUTC: "+dateUTC1);
}

I saw that both statements print the same value i.e.

today: Thu Aug 30 14:48:56 PDT 2012
todayUTC: Thu Aug 30 14:48:56 PDT 2012

Can anybody suggest what am I missing in UTC function that I am getting local timezone date.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:32:52+00:00Added an answer on June 10, 2026 at 8:32 pm

    Java uses the default Locale while printing and that is why you see that behavior. Use code like below to format and print it in the locale/format you want. Remember

    • When you create a Date object, it is always in UTC.
    • Display the date in the Locale of the user.
    • Store the date in UTC.

    Code

    final SimpleDateFormat sdf = new SimpleDateFormat("the format you want");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    final String utcTime = sdf.format(new Date());
    

    You doesn’t need both today() and todayUTC() methods. keep and like below

    public static Date nowInUTC() 
    {
      return new Date();
    }
    

    You doesn’t need to test anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a program written in C++ in which one or two functions
I have two user controls I have some functions written on those two controls.
I have two functions written in VB.NET: 1) The first function (call it GetValues())
I have written two functions setSes() and getSes() and here I have written session_start()
...not sure calculated was the right word...I have written two functions, the second of
I have written two jQuery functions, the simplified version of which run thus: $('button.class').not('.selected').on('click',
I have written two short tests and compiled both with g++ -S (gcc version
I have written two scripts where one script calls subprocess.Popen to run a terminal
I have written two pieces of code which I intended to have identical outputs,
I have written an app in C which expects two lines at input. First

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.