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 1089209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:11:13+00:00 2026-05-16T23:11:13+00:00

How can I output the current date and time with the defaulttimezone? When I

  • 0

How can I output the current date and time with the defaulttimezone?
When I use following code I always get the time in GMT. Is it possible to convert NSDate to the defaulttimezone? I can’t use the NSDateFormatter because I need an NSDate Object with the correct time.

NSDate *date = [NSDate date];
NSLog(@"Time: %@", date);

Output: 2010-09-26 12:07:12 TimeTest[2641:207] Time: 2010-09-26 12:07:12 GMT

Update:
When I have to return an NSDate object with the right time, how can I use NSDateFormatter with setTimeZone?

 NSDate* date = [NSDate date];

 NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
 [formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
 NSTimeZone *tz = [NSTimeZone timeZoneWithName:@"MESZ"];
 [formatter setTimeZone:tz];

 NSString *datestr = [formatter stringFromDate:date];
 NSLog(@"%@", datestr);

 NSDate *datenew = [formatter dateFromString:str];
 NSLog(@"%@", datenew);

The first NSLog outputs the correct time but when I want to make an NSDate object with the correct time I get the wrong time again.

  • 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-05-16T23:11:14+00:00Added an answer on May 16, 2026 at 11:11 pm

    I can’t use the NSDateFormatter because I need an NSDate Object with the correct time.

    That doesn’t make any sense. NSDate represents a single point in time. It does not know nor care about time zones. For example, Today, 12:00 GMT and Today, 06:00 –0600 would be represented by one and the same NSDate object.

    To display a date in a specific timezone, use NSDateFormatter, specifically its setTimeZone: method.

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

Sidebar

Related Questions

I'm trying to output the current date and time using this code: $theDate =
I can output a locale sensitive time format using strftime('%X') , but this always
How can I get the current Windows time in a PHP script? Using time()
how can I change the output of the following to something like 2 hours
I know Date is mostly deprecated, but I still use it form time to
I have the following code on the timeline, but when I try and output
I need the current date time in the format YYYYMMDDHHMISSMIS Example: 20110723233747607 By using
Is it possible to get the first / last date of a week using
I need to get the UTC offset of the current time zone in Perl
I have the below program to obtain current date and time. int main(void) {

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.